Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 25

Thread: Solved: before print

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Solved: before print

    can anyone tell me if in word 2000 is there Before_Print event available as I cant seem to find one?

    Cheers

    Gibbo

  2. #2
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    Hi Gibbo. I'm sorry but my version is 2002. Try to type "Documentbeforeprint" in the VBE guide.

    Bye

  3. #3
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    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
    Last edited by Aussiebear; 03-26-2023 at 01:22 AM. Reason: Adjusted the code tags

  4. #4
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    Have you put it in a class module with the declaration "Public WithEvents appWord as Word.Application" at the top?

  5. #5
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Yes

    Have class1 Class Module as below

    [VBA] 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 [/VBA]

    cheers

    gibbo

  6. #6
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    have you a standard module where you make a new istance?

  7. #7
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    No nothing in a standard module at the moment?

  8. #8
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    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
    Last edited by Aussiebear; 03-26-2023 at 01:23 AM. Reason: Adjusted the code tags

  9. #9
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    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
    Last edited by Aussiebear; 03-26-2023 at 01:23 AM. Reason: Adjusted the code tags

  10. #10
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    what does it say as error?

  11. #11
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Doesnt error, just doesnt give me my messagebox before printing

  12. #12
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    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

  13. #13
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    It should work. Try to run the proc register event handler and immediately after click the print button.

  14. #14
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    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

  15. #15
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    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.

  16. #16
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    As you can see the proc is called when the document is opened

  17. #17
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    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

  18. #18
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    Ok. We'll get in contact. Bye

  19. #19
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    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.
    Last edited by Aussiebear; 03-26-2023 at 01:24 AM. Reason: Adjusted the code tags

  20. #20
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Thanks Marcster That worked great

    Gibbo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •