Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    test to check if Cancel button pressed (Office XPSP3)

    HI I have the following code to call up Words native print dialog box

    Dim dlgPrint As Dialog
    Set dlgPrint = Dialogs(wdDialogFilePrint)
    dlgPrint.Update
    dlgPrint.PrintToFile = 0
    If dlgPrint.Display = -1 Then
    dlgPrint.Execute
    End If

    I want my code to check if the cancel button is pressed, (or the ESC key to cancel)
    ive added 1 line of code in the below....

    Dim dlgPrint As Dialog
    Set dlgPrint = Dialogs(wdDialogFilePrint)
    dlgPrint.Update
    dlgPrint.PrintToFile = 0
    If dlgPrint.Display = -1 Then
    dlgPrint.Execute

    Else: MsgBox "cancel"

    End If


    however should i be testing on 'If dlgPrint.Display = 0 Then'
    & if yes when I run the below code it displays the Word native print dialog box twice due to the code dlgPrint.Display

    Dim dlgPrint As Dialog
    Set dlgPrint = Dialogs(wdDialogFilePrint)
    dlgPrint.Update
    dlgPrint.PrintToFile = 0
    If dlgPrint.Display = -1 Then
    dlgPrint.Execute

    elseIf dlgPrint.Display = 0 Then MsgBox "cancel"

    End If

    any ideas? diana

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: test to check if Cancel button pressed (Office

    The middle version should work. It doesn't work?

    The last version displays the dialog twice. Even though you are calling the .Display method as part of an expression, it is just as though are your executing a command (like calling MsgBox() as part of an expression).

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: test to check if Cancel button pressed (Office XPSP3)

    The Select Case statement is ideal for this:

    Dim dlgPrint As Dialog
    Set dlgPrint = Dialogs(wdDialogFilePrint)
    dlgPrint.Update
    dlgPrint.PrintToFile = 0
    Select Case dlgPrint.Display
    Case -1
    dlgPrint.Execute
    Case 0
    MsgBox "cancel"
    Case Else
    ' ignore or insert extra code here
    End Select

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: test to check if Cancel button pressed (Office XPSP3)

    hey hans, jefferson

    neat code hans...
    jefferson i like to cater for all scenarios, ( & not leave it to chance)...

    many thanks for you help....Diana :-)

Posting Permissions

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