PDA

View Full Version : Solved: before print



gibbo1715
11-02-2005, 02:31 AM
can anyone tell me if in word 2000 is there Before_Print event available as I cant seem to find one?

Cheers

Gibbo

ALe
11-02-2005, 02:43 AM
Hi Gibbo. I'm sorry but my version is 2002. Try to type "Documentbeforeprint" in the VBE guide.

Bye

gibbo1715
11-02-2005, 03:11 AM
Hi ALe

Thanks for the reply
my help said the following should work for me


Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
a = MsgBox("Have you checked the " _
& "printer for letterhead?", _
vbYesNo)
If a = vbNo Then Cancel = True
End Sub

But doesnt seem to do anything for me, any ideas what im missing here

ALe
11-02-2005, 03:29 AM
Have you put it in a class module with the declaration "Public WithEvents appWord as Word.Application" at the top?

gibbo1715
11-02-2005, 03:36 AM
Yes

Have class1 Class Module as below

Public WithEvents appWord As Word.Application
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
a = MsgBox("Have you checked the " _
& "printer for letterhead?", _
vbYesNo)
If a = vbNo Then Cancel = True
End Sub

cheers

gibbo

ALe
11-02-2005, 03:39 AM
have you a standard module where you make a new istance?

gibbo1715
11-02-2005, 03:42 AM
No nothing in a standard module at the moment?

ALe
11-02-2005, 03:42 AM
Put this in a standard module and run the procedure "Register_Event_Handler"


Option Explicit
Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.appWord = Word.Application
End Sub



Be sure that your class module is named EventClassModule

gibbo1715
11-02-2005, 03:46 AM
Tried as above but still doesnt work for me?
Module1


Option Explicit
Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.appWord = Word.Application
End Sub

EventClassModule

Public WithEvents appWord As Word.Application
Private Sub App_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
a = MsgBox("Have you checked the " _
& "printer for letterhead?", _
vbYesNo)
If a = vbNo Then Cancel = True
End Sub

Cheers

Gibbo

ALe
11-02-2005, 03:47 AM
what does it say as error?

gibbo1715
11-02-2005, 03:52 AM
Doesnt error, just doesnt give me my messagebox before printing

gibbo1715
11-02-2005, 03:54 AM
Just tried playing with it a bit, if i ask it just to display a message nothing happens, if I have my original code it does print but no message, very strange

ALe
11-02-2005, 03:55 AM
It should work. Try to run the proc register event handler and immediately after click the print button.

gibbo1715
11-02-2005, 04:00 AM
Nope didnt work for some reason

I ve ammeded my code to just display a message box, it shows in the status bar it is printing but doesnt actually print and doesnt show the message box,

also tried writing to a bookmark before print, that didnt work either.

Also tried calling another sub again no joy

Very confusing

ALe
11-02-2005, 04:04 AM
I'll send my file. Check it if it works alone so we understand if the problem is your word version or your own code.

ALe
11-02-2005, 04:04 AM
As you can see the proc is called when the document is opened

gibbo1715
11-02-2005, 04:09 AM
thanks ALe, i cant check it until this evening as i dont have winzip at work but will try it then and get back to you

Thanks for your help

Gibbo

ALe
11-02-2005, 04:11 AM
Ok. We'll get in contact. Bye

Marcster
11-02-2005, 08:19 AM
Try puting this in the ThisDocument module (tested in Word 2000):


Sub FilePrint()
'Runs when user selects Print from the File menu
Call AskMsg
End Sub

Sub FilePrintDefault()
'Runs when user clicks on the printer toolbar button
Call AskMsg
End Sub

Sub AskMsg()
Select Case MsgBox("Have you checked the printer for letterhead?", vbYesNo Or vbQuestion Or vbDefaultButton1, "Info")
Case vbYes
MsgBox "Ok you can now print"
Dialogs(wdDialogFilePrint).Show
Case vbNo
Exit Sub
End Select
End Sub


Marcster.

gibbo1715
11-02-2005, 08:27 AM
Thanks Marcster That worked great

Gibbo

ALe
11-02-2005, 09:23 AM
Why FilePrint and FilePrintDefault are run? How does the connection with the print buttons works?

Marcster
11-02-2005, 09:58 AM
As a side point, you can capture the events for any of the buttons, function keys, short-cut keys and menu items in Word.
Sample subs to be put in the ThisDocument module:

Sub AppMinimize()
MsgBox "You cannot minimize Word."
End Sub

Sub ViewVBCode()
MsgBox "You cannot view the code." 'You can if you have the VBE already open though.
End Sub

Sub Help()
'Overrides the F1 function key.
MsgBox "You cannot see Help."
End Sub

Sub FileSendMail()
'Overrides the Send To Mail Recipient (as Attachment) command on the File menu.
MsgBox "FileSendMail"
End Sub

Marcster.

gibbo1715
11-02-2005, 10:05 AM
Marcster that is so useful,

Gibbo

ALe
11-02-2005, 10:19 AM
Wow. I didn't know. 2 questions:
1 how do you get the exact name for each button/procs?
2 is it possible also for excel, powerpoint, access?

ALe
11-02-2005, 10:39 AM
As far as I know, it works only for Word. I found it mentioned in MSDN under the words "visual basic equivalents"