I found this API code for 64 Bit Sytem and adapted it . However, Haluk's Solution is far more simple and works perfectly
Option Explicit
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function IsWindow Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function InvalidateRect Lib "user32" (ByVal hwnd As LongPtr, _
lpRect As LongPtr, ByVal bErase As LongPtr) As LongPtr
Private Declare PtrSafe Function UpdateWindow Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
Public Function fncScreenUpdating(State As Boolean, Optional Window_hWnd As LongPtr = 0) As LongPtr
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
Public Sub PrintChequeAdvices()
Dim ws As Worksheet
Dim cell As Range
fncScreenUpdating State:=False, Window_hWnd:=GetDesktopWindow()
Application.DisplayAlerts = False 'suppress print message
Application.ScreenUpdating = False 'suppress screen updating
Application.DisplayStatusBar = False 'suppress status bar message
Application.PrintCommunication = False 'suppress printing messages
Application.StatusBar = "Printing..." 'suppress printing message bar
For Each ws In Worksheets
If ws.Index >= 3 And ws.Range("C29").Value <> 0 Then
With ws.PageSetup
.PrintArea = "$A$1:$E$38"
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.Orientation = xlLandscape ' set the page orientation to Landscape
End With
For Each cell In ws.Range("A1:E38")
cell.Borders.LineStyle = xlContinuous
cell.Borders.Weight = xlThin
Next cell
Application.StatusBar = "Printing " & ws.Name & "..."
ws.PrintOut Preview:=False 'print without preview
End If
Next ws
Application.DisplayAlerts = True 'enable display alerts
Application.ScreenUpdating = True 'enable screen updating
Application.DisplayStatusBar = True 'enable status bar message
Application.PrintCommunication = True 'enable printing messages
Application.StatusBar = False 'clear the status bar
fncScreenUpdating State:=True, Window_hWnd:=GetDesktopWindow()
End Sub
Bookmarks