Display all worksheets of a workbook in listbox and print specific worksheet

Home More Excel (VBA) Training Videos

How to display all worksheets of a workbook in a listbox and then print a specific worksheet is based on a question from one of our youtube channel subscribers:

"Comment on your video: Print specific worksheet from Excel Workbook 'There any way, when you click print a window said, select sheet to print: on the window you see all names from de workbook and you just want to click it.' Henri"

Henri most probably means whether there is a way to display all the worksheets of a workbook and then select a worksheet from the list for printing.

We insert a userform and the userform we place a listbox control and a command button.

The listbox is populated with the sheetnames from the workbook by using a 'do until' loop as shown in the complete macro code below:

Private Sub UserForm_Initialize()
Dim n As Integer
Do n = n + 1
ListBox1.AddItem Sheets(n).Name
Loop Until n = Worksheets.Count
End Sub

For printing a specific sheet we use a command that is appropriately coded as shown below:

Private Sub CommandButton1_Click()
End Sub

As you can see the VBA code for both the controls is not difficult to understand.

Watch the Excel VBA training video below to see how the complete process is implemented:

Watch the video on our youtube channel

Home More Excel (VBA) Training Videos