Hi,
I have code for a userform that reads all visible worksheets. The userform has a print command button that will display a multi select list box containing the names of all the visible worksheets. Currently I have the print command set to ".printout" for all selected sheets. However, I would like to give the user the option to select their printer instead of just printing to the default printer. I put in various versions of the "applications.dialogs(xldialogprintersetup).show" but it seems because of the loop that the user will have to select the printer for each sheet selected.
Is there any way to have the user only select their printer once?
Private Sub UserForm_Initialize() 'Print Selected Forms Pop Up Box
With PrintSelectedForms 'Display in middle of window
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
End With
'Display all visible worksheets
'Worksheets visible if form is selected
Dim ws As Worksheet
ListBox1.Clear
For Each ws In Worksheets
If ws.Visible = True Then
ListBox1.AddItem ws.Name
End If
Next ws
End Sub
Private Sub CommandButton1_Click() 'Print Select Forms
Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Sheets(ListBox1.List(i)).PrintOut
End If
Next i
Unload PrintSelectedForms
End Sub
Thanks in advance
I have code for a userform that reads all visible worksheets. The userform has a print command button that will display a multi select list box containing the names of all the visible worksheets. Currently I have the print command set to ".printout" for all selected sheets. However, I would like to give the user the option to select their printer instead of just printing to the default printer. I put in various versions of the "applications.dialogs(xldialogprintersetup).show" but it seems because of the loop that the user will have to select the printer for each sheet selected.
Is there any way to have the user only select their printer once?
Private Sub UserForm_Initialize() 'Print Selected Forms Pop Up Box
With PrintSelectedForms 'Display in middle of window
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
End With
'Display all visible worksheets
'Worksheets visible if form is selected
Dim ws As Worksheet
ListBox1.Clear
For Each ws In Worksheets
If ws.Visible = True Then
ListBox1.AddItem ws.Name
End If
Next ws
End Sub
Private Sub CommandButton1_Click() 'Print Select Forms
Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Sheets(ListBox1.List(i)).PrintOut
End If
Next i
Unload PrintSelectedForms
End Sub
Thanks in advance