Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Worksheet from Listbox selection 1

Status
Not open for further replies.

bluegnu

Technical User
Sep 12, 2001
131
GB
OK, I have a listbox which is populated with a list of worksheet names in my workbook.

People can select multiple sheets names in the listbox. I would then like to be able to press a button which will print the selected sheets but I'm struggling to get anywhere with this.

What code would I use to convert the selected listbox values into worksheets so I can use Worksheets("Selectedsheet").PrintOut?

thanks
 
Hi,

You could use something like this ..

Code:
Private Sub CommandButton1_Click() 'PRINT
    Dim i As Long
    For i = 0 To Me.ListBox1.ListCount - 1
        If Me.ListBox1.Selected(i) = True Then
            Sheets(Me.ListBox1.List(i)).PrintOut
        End If
    Next i
End Sub

Private Sub CommandButton2_Click() 'CLOSE
    Unload Me
End Sub

Private Sub UserForm_Initialize() 'OPEN
    Dim i As Long
    For i = 1 To ThisWorkbook.Worksheets.Count
        Me.ListBox1.AddItem ThisWorkbook.Worksheets(i).Name
    Next i
End Sub

-----------
Regards,
Zack Barresse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top