Userform with option buttons to print selected sheets

R

Roger on Excel

Can anyone help me with code to help me buid a userform in which a user
selects the sheets in the workbook to print using option buttons ?

Once the user has selected the sheets another button prints them

Can anyone help?

Thankyou,

Roger
 
J

Jacob Skaria

How about using a combo box. Place a combobox and command button in a
userform and try the below code


Private Sub CommandButton1_Click()
ThisWorkbook.Sheets(Me.ComboBox1.Text).PrintOut Copies:=1, Collate:=True
End Sub

Private Sub UserForm_Initialize()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
Me.ComboBox1.AddItem ws.Name
Next
End Sub
 
H

Harald Staff

And if you want multiple choice, use a listbox. Modified code:

Private Sub CommandButton1_Click()
Dim L As Long
For L = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(L) = True Then
ThisWorkbook.Sheets(Me.ListBox1.List(L)).PrintOut Copies:=1, Collate:=True
End If
Next
End Sub

Private Sub UserForm_Initialize()
Dim ws As Worksheet
Me.ListBox1.MultiSelect = fmMultiSelectMulti
For Each ws In ThisWorkbook.Sheets
Me.ListBox1.AddItem ws.Name
Next
End Sub

HTH. Best wishes Harald
 
R

Roger on Excel

Thanks Harald,

This solution with the list box is perfect for me

Best regards

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top