Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"