Sub PromptPrinter()

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,107
Office Version
  1. 365
Platform
  1. Windows
Hi Al,

I'm using the following code to call a printer.



Code:
Sub PromptPrinter()


Application.Dialogs(xlDialogPrinterSetup).Show


End Sub


How do I add if the user clicks the
button that the sub can provide a Msgbox "Cancel" ?


Thank you!
pinaceous
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Is this what you need?

Code:
Sub PromptPrinter()
Dim x
x = Application.Dialogs(xlDialogPrinterSetup).Show
If x = False Then MsgBox "Cancelled"
End Sub
 
Upvote 0
Hey Scott,

That works for the application. In testing out the sub;

Could I ask in lieu of the message box that when the user clicks the cancel button that the sub does nothing?

For example, for the application dialogue, if the user clicks the cancel button the sub does not in fact cancel but skips this step or ignores the cancellation.

Is this possible?

Many thanks,
Paul
 
Last edited:
Upvote 0
So you're trying to not allow Cancel?

How about this?

Code:
Sub PromptPrinter()
Do Until x
    x = Application.Dialogs(xlDialogPrinterSetup).Show
Loop
End Sub
 
Upvote 0
Hi Scott,

That looks like it would do it!

Curious, is there another way to accomplish this without looping it?

Thanks,
Paul
 
Upvote 0
Yes, but this won't loop very much. It only loops if Cancel is pressed.
This loops until x is True meaning a printer was selected.

But here you go:

Code:
Sub PromptPrinter()
x = Application.Dialogs(xlDialogPrinterSetup).Show
If x = False Then Call PromptPrinter
End Sub
 
Last edited:
Upvote 0
Hi Scott,

Gotcha. Thanks for explaining the concept and for providing an alternate method.

I'm going to give it a go now.

Take care,
Paul
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,247
Members
448,879
Latest member
oksanana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top