|
-
Apr 9th, 2003, 02:49 AM
#1
Thread Starter
Lively Member
Word Events
I am using the following code to intercept the print event in word all works fine until you have more than one document open with the macro in then you get the message twice. Does anyone have any bright ideas how to stop this happening.
Thanks in advance (fingers crossed)
VB Code:
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
usrType = "HKEY_CURRENT_USER"
location = regget(usrType & "\SOFTWARE\M\User Location")
If Len(location) = 0 Then
location = regget("HKEY_LOCAL_MACHINE\SOFTWARE\M\Station Location")
End If
If Left(LCase(location), 6) = "london" Then
msg = "Only print the draft copy?" & vbCrLf & vbCrLf
msg = msg & "Yes" & vbTab & "- Print only the draft copy." & vbCrLf
msg = msg & "No" & vbTab & "- Print both copies." & vbCrLf
msg = msg & "Cancel" & vbTab & "- Print using your word setting."
clicked = MsgBox(msg, vbYesNoCancel)
If clicked = vbYes Or clicked = vbNo Then
'Cancel the existing print job
Cancel = True
If clicked = vbNo Then
' Config the tray as needed for client copy
Doc.PageSetup.FirstPageTray = wdPrinterLowerBin
Doc.PageSetup.OtherPagesTray = wdPrinterUpperBin
' Print the client copy
Doc.PrintOut Copies:=1
End If
' Config the trays as needed for the file copy
Doc.PageSetup.FirstPageTray = wdPrinterLargeCapacityBin
Doc.PageSetup.OtherPagesTray = wdPrinterLargeCapacityBin
'Print the file copy
Doc.PrintOut Copies:=1
End If
End If
End Sub
-
Apr 9th, 2003, 03:22 AM
#2
How are you calling this App_DocumentBeforePrint procedure?
-
Apr 9th, 2003, 03:28 AM
#3
Thread Starter
Lively Member
I never call it its runs like the Document_Open events in this case before the user prints this event is called.
This is the code to register the event
VB Code:
Dim X As New PrinterModule
Sub Register_Event_Handler()
Set X.App = Word.Application
End Sub
-
Apr 9th, 2003, 05:53 AM
#4
Hyperactive Member
You could create a global variable thats an integer when the code gets executed detect how many documents are open and then run your code and set the global variable to the remander of documents left.... then each time you get further calls just keep reducing the global variable and skip the code with an if... else... block. Make sure you reduce the global variable to 0 and then your code will work only the onetime needed.
Hope that helps
Example:
Code:
public intCount as integer
public sub....
if intCount = 0 then
intCount = Documents.Count
.... execute code
else
intCount = intCount - 1
end if
end sub
See ya later,
-=XQ=-
"Reality is merely an illusion, albeit a very persistent one. "
- Albert Einstein (1879-1955)
This is the coolest site ever!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|