Sub PromptPrinter()

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
589
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
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,901
Office Version
365, 2010
Platform
Windows
Is this what you need?

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

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
589
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:

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,901
Office Version
365, 2010
Platform
Windows
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
 

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
589
Hi Scott,

That looks like it would do it!

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

Thanks,
Paul
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,901
Office Version
365, 2010
Platform
Windows
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:

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
589
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
 

Forum statistics

Threads
1,085,714
Messages
5,385,415
Members
401,944
Latest member
Hellodoublev

Some videos you may like

This Week's Hot Topics

Top