M
Michael Malinsky
I have tried the methods posted in this NG to freeze the screen when I
update print setting via VBA. I have the following code included as an
add-in:
-----------------
Option Explicit
Private Declare Function LockWindowUpdate Lib "USER32" (ByVal hwndLock
As Long) As Long
Private Declare Function GetDesktopWindow Lib "USER32" () As Long
-----------------
Private Sub Print_Draft()
Dim x As Integer
Dim sh As Object
Dim mycontrol As Object
WindowUpdating (False) 'to freeze the screen
Set mycontrol = CommandBars("Worksheet Menu Bar").Controls("Time
Savers")
If mycontrol.Controls("Print Draft").State = msoButtonUp Then
'To change printer settings to print draft watermark.
Application.SendKeys ("^p")
For x = 1 To 6
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
For x = 1 To 2
Application.SendKeys ("{LEFT}")
Next x
For x = 1 To 3
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
For x = 1 To 21
Application.SendKeys ("{DOWN}")
Next x
Application.SendKeys ("{RIGHT}")
For x = 1 To 3
Application.SendKeys ("{DOWN}")
Next x
Application.SendKeys ("~")
Application.SendKeys ("{LEFT}")
Application.SendKeys ("{TAB}")
Application.SendKeys ("~")
Application.SendKeys ("{TAB}")
Application.SendKeys ("~")
For x = 1 To 11
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
mycontrol.Controls("Print Draft").State = msoButtonDown
'To change printer settings to remove print draft watermark.
ElseIf mycontrol.Controls("Print Draft").State = msoButtonDown Then
Application.SendKeys ("^p")
For x = 1 To 6
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
For x = 1 To 2
Application.SendKeys ("{LEFT}")
Next x
For x = 1 To 3
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
For x = 1 To 21
Application.SendKeys ("{DOWN}")
Next x
Application.SendKeys ("{RIGHT}")
For x = 1 To 3
Application.SendKeys ("{DOWN}")
Next x
For x = 1 To 2
Application.SendKeys ("{UP}")
Next x
Application.SendKeys ("~")
Application.SendKeys ("{LEFT}")
Application.SendKeys ("{TAB}")
Application.SendKeys ("~")
Application.SendKeys ("{TAB}")
Application.SendKeys ("~")
For x = 1 To 11
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
mycontrol.Controls("Print Draft").State = msoButtonUp
End If
WindowUpdating (True) 'to unfreeze the screen
End Sub
--------------------
Sub WindowUpdating(Enabled As Boolean)
'Completely Locks the Whole Application Screen Area, including dialogs
and the mouse.
Dim Res As Long
If Enabled Then
LockWindowUpdate 0 'Unlock screen area
Else
Res = LockWindowUpdate(GetDesktopWindow) 'Lock at desktop
level
End If
End Sub
---------------------
The code itself works fine, but I still see the various dialog boxes
popping up based on the SendKeys commands I used.
Am I missing something?
TIA,
Mike.
update print setting via VBA. I have the following code included as an
add-in:
-----------------
Option Explicit
Private Declare Function LockWindowUpdate Lib "USER32" (ByVal hwndLock
As Long) As Long
Private Declare Function GetDesktopWindow Lib "USER32" () As Long
-----------------
Private Sub Print_Draft()
Dim x As Integer
Dim sh As Object
Dim mycontrol As Object
WindowUpdating (False) 'to freeze the screen
Set mycontrol = CommandBars("Worksheet Menu Bar").Controls("Time
Savers")
If mycontrol.Controls("Print Draft").State = msoButtonUp Then
'To change printer settings to print draft watermark.
Application.SendKeys ("^p")
For x = 1 To 6
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
For x = 1 To 2
Application.SendKeys ("{LEFT}")
Next x
For x = 1 To 3
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
For x = 1 To 21
Application.SendKeys ("{DOWN}")
Next x
Application.SendKeys ("{RIGHT}")
For x = 1 To 3
Application.SendKeys ("{DOWN}")
Next x
Application.SendKeys ("~")
Application.SendKeys ("{LEFT}")
Application.SendKeys ("{TAB}")
Application.SendKeys ("~")
Application.SendKeys ("{TAB}")
Application.SendKeys ("~")
For x = 1 To 11
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
mycontrol.Controls("Print Draft").State = msoButtonDown
'To change printer settings to remove print draft watermark.
ElseIf mycontrol.Controls("Print Draft").State = msoButtonDown Then
Application.SendKeys ("^p")
For x = 1 To 6
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
For x = 1 To 2
Application.SendKeys ("{LEFT}")
Next x
For x = 1 To 3
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
For x = 1 To 21
Application.SendKeys ("{DOWN}")
Next x
Application.SendKeys ("{RIGHT}")
For x = 1 To 3
Application.SendKeys ("{DOWN}")
Next x
For x = 1 To 2
Application.SendKeys ("{UP}")
Next x
Application.SendKeys ("~")
Application.SendKeys ("{LEFT}")
Application.SendKeys ("{TAB}")
Application.SendKeys ("~")
Application.SendKeys ("{TAB}")
Application.SendKeys ("~")
For x = 1 To 11
Application.SendKeys ("{TAB}")
Next x
Application.SendKeys ("~")
mycontrol.Controls("Print Draft").State = msoButtonUp
End If
WindowUpdating (True) 'to unfreeze the screen
End Sub
--------------------
Sub WindowUpdating(Enabled As Boolean)
'Completely Locks the Whole Application Screen Area, including dialogs
and the mouse.
Dim Res As Long
If Enabled Then
LockWindowUpdate 0 'Unlock screen area
Else
Res = LockWindowUpdate(GetDesktopWindow) 'Lock at desktop
level
End If
End Sub
---------------------
The code itself works fine, but I still see the various dialog boxes
popping up based on the SendKeys commands I used.
Am I missing something?
TIA,
Mike.