Sub CommandButtomln13_Click() Dim fileOK As Boolean Dim sPrinter As String With Application sPrinter = .ActivePrinter fileOK = .Dialogs(xlDialogPrint).Show End With If fileOK = True Then Me.PrintForm Application.ActivePrinter = sPrinter End IfEnd Sub
I have the above code under a button click sub. The purpose is to print the particular userform (the button is on)
I am showing printer dialog in an effort to switch printers should it be required. However, its not working. Regardless of what printer I choose, the userform is being printed on my default printer.
Any help is appreciated (no API calls please as user could be 32/64 bit)
Thanks!
Visual Basic Classic
Last Comment
shorvath
8/22/2022 - Mon
Barry62
try reversing the printform and activeprinter statements:
If fileOK = True Then Application.ActivePrinter = sPrinter Me.PrintForm End If
Thanks it worked. Only thing is that 'oWord' is not defined
Public Sub ChangeDefaultPrinter(pName As String) Dim oWord As Object Set oWord = CreateObject("Word.Application") oWord.Visible = False oWord.WordBasic.FilePrintSetup Printer:=pName, DoNotSetAsSysDefault:=0 Set oWord = NothingEnd Sub
Open in new window