ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   LockWindowUpdate (https://www.excelbanter.com/excel-programming/326191-lockwindowupdate.html)

Michael Malinsky[_2_]

LockWindowUpdate
 
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.



All times are GMT +1. The time now is 01:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com