Capture PrintDialog's cancel

Z

zSplash

I use the following code:
With Dialogs(wdDialogFilePrint)
.Range = wdPrintCurrentPage
.show
End With
Application PrintOut

If a user clicks "cancel", how do I know that so that I can exit out of the
print process?

TIA
 
C

Chad DeMeyer

The Show method returns a value indicating what button was pressed.

If .Show = -1 Then Exit Sub '-1 = Cancel button clicked

Regards,
Chad DeMeyer
 
Z

zSplash

Thanks for helping, Chad.

I'm dumber than a rock. I tried the following, and it just kept "showing"
the dialog box, but would not let me "get" the value of ".show":
With Dialogs(wdDialogFilePrint)
.Range = wdPrintCurrentPage
.show
if .show = -1 then
End
End If
End With
If I clicked on Cancel three times, it finally ended the sub. After the
first "cancel", if I hit OK (the second time the dialog box showed), it just
printed as if I'd never said Cancel. Any suggestions?

st.
 
C

Chad DeMeyer

Learning something new is not the same as being dumber than a rock :)

When you get the return value of the .Show method in the If statement, you
are actually calling the method a second time. Replace the four lines of
code:

.show
if .show = -1 then
end
end if

with just the lines

if .show = -1 then
end
end if

or, if you don't need to do anything else before ending the procedure, you
can condense it to one line:

if .show = -1 then end

Hope that clarifies it for ya.

Regards,
Chad DeMeyer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top