Option Explicit
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx _
Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function GetDlgItem _
Lib "user32" _
(ByVal hDlg As Long, _
ByVal nIDDlgItem As Long) As Long
Private Declare Function EnableWindow _
Lib "user32" _
(ByVal hwnd As Long, _
ByVal fEnable As Long) As Long
Public Declare Function SetTimer _
Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer _
Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Public lTimerID As Long
Public Sub DisablePrint()
Dim lXlHwnd As Long
Dim lPrintPrevHwnd As Long
Dim lPrintButtonHwnd As Long
[COLOR=seagreen]'use the timer once so remove it[/COLOR]
KillTimer 0, lTimerID
[COLOR=seagreen]'get the excel window hwnd[/COLOR]
lXlHwnd = FindWindow("XLMAIN", Application.Caption)
[COLOR=seagreen]'get the printpreview window hwnd[/COLOR]
lPrintPrevHwnd = FindWindowEx(lXlHwnd, 0, "EXCELC", vbNullString)
[COLOR=seagreen]'get the printpreview print button window hwnd[/COLOR]
[COLOR=seagreen] '"3" being the unique ID of the print button (found by trial & error)[/COLOR]
lPrintButtonHwnd = GetDlgItem(lPrintPrevHwnd, 3)
[COLOR=seagreen]'finally,disable the print button[/COLOR]
EnableWindow lPrintButtonHwnd, False
End Sub