I've been using userforms to print labels, works great! I call a userform by double clicking a row of data in a certain sheet and the userform is filled with that data, then the userform is printed from a command button on the userform using this method:
Private Sub CommandButton1_Click()
Dim fileOK As Boolean
Dim sPrinter As String
With Application
sPrinter = .ActivePrinter
fileOK = .Dialogs(xlDialogPrinterSetup).Show
End With
If fileOK = True Then
ChangeDefaultPrinter (Application.ActivePrinter)
CommandButton1.Visible = False
UserForm3.PrintForm
CommandButton1.Visible = True
ChangeDefaultPrinter (sPrinter)
End If
End Sub
Public Sub ChangeDefaultPrinter(pName As String)
Dim oWord
Set oWord = CreateObject("Word.Application")
oWord.WordBasic.FilePrintSetup Printer:=pName, DoNotSetAsSysDefault:=0
oWord.Quit
Set oWord = Nothing
End Sub
That method is the only one I've found that doesn't involve API coding and that doesn't change the default printer of windows. That's normally not an issue just printing to the selected printer, however with this new userform I need to adjust printer settings prior to printing. I just discovered that changing the printer settings from the print dialog that opens doesn't affect the printed userform. However it changes the printer settings for the excel file. So the userform still prints to the selected printer but not with the selected settings, i.e. different printer tray. Is there a way to do that by adding something into the code above?
Thanks!
Bookmarks