On 2002-07-02 19:54, cutter45 wrote:
I have a macro that prints commission reports by scrolling through a list of sales reps, then printing the report. I would like to turn of the "Now Printing" message that pops up as each report is sent off to the printer.
I've tried Application.DisplayAlerts = False and also Application.ScreenUpdating = False
Neither do the trick. I'm assuming this message is Windows related and requires a different approach.
Thanks for any help!
You do indeed need a differnt approach.
Here is how you can do it. Credit Tom Olgilvy
Comments added by me.
Example of how to use @ the end.
<pre/>
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
'// The SendMessage function sends the specified message to a window or windows.
'// The function calls the window procedure for the specified window and does not
'// return until the window procedure has processed the message.
'// The PostMessage function, in contrast, posts a message to a thread’s message
'// queue and returns immediately.
'//
'// PARAMETERS:
'//
'// hwnd
'// Identifies the window whose window procedure will receive the message.
'// If this parameter is HWND_BROADCAST, the message is sent to all top-level
'// windows in the system, including disabled or invisible unowned windows,
'// overlapped windows, and pop-up windows; but the message is not sent to child windows.
'// Msg
'// Specifies the message to be sent.
'// wParam
'// Specifies additional message-specific information.
'// lParam
'// Specifies additional message-specific information.
'//////////////////////////////////////////////////////////////////////////
'// The IsWindow function determines whether the specified window handle
'// identifies an existing window.
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
'// PARAMETERS:
'// hWnd
'// Specifies the window handle.
'//////////////////////////////////////////////////////////////////////////
'//
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, _
lpRect As Long, ByVal bErase As Long) As Long
Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Public Function fncScreenUpdating(State As Boolean, Optional Window_hWnd As Long = 0)
Const WM_SETREDRAW = &HB
Const WM_PAINT = &HF
If Window_hWnd = 0 Then
Window_hWnd = GetDesktopWindow()
Else
If IsWindow(hwnd:=Window_hWnd) = False Then
Exit Function
End If
End If
If State = True Then
Call SendMessage(hwnd:=Window_hWnd, wMsg:=WM_SETREDRAW, wParam:=1, lParam:=0)
Call InvalidateRect(hwnd:=Window_hWnd, lpRect:=0, bErase:=True)
Call UpdateWindow(hwnd:=Window_hWnd)
Else
Call SendMessage(hwnd:=Window_hWnd, wMsg:=WM_SETREDRAW, wParam:=0, lParam:=0)
End If
End Function
'-----------------------------
Sub PrintDirect()
fncScreenUpdating State:=False
ActiveWindow.SelectedSheets.PrintOut Copies:=1
fncScreenUpdating State:=True
End Sub
'-----------------------------
</pre>