Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printing multiple sheets triggered by the use of checkbox's on the userform

1 view
Skip to first unread message

John Shikella

unread,
May 14, 2003, 5:15:16 PM5/14/03
to
Hello all, I am an avid reader of the posts here on the site but have
never posted until now. This is my number one source of help for VB
so I thank you for the past help you all have provided and hopefully
the future.

Here's the deal: I have three sheets in my workbook "New Rates
Calculator.xls" named "Home Delivery", "express", and "ground".

I have created a userform with three checkboxes for "Home delivery",
"Express", and "Ground". Now, I want the user to be able to check
these boxes (one at a time or all three if need be) and then have the
command button combine the selected sheets into a print preview. This
question includes how do I add to an array of sheets.

I am not a beginner and have scoured the newsgroups for a solution but
just can't seem to figure this out. Any help is greatly appreciated.

Ron de Bruin

unread,
May 14, 2003, 5:32:24 PM5/14/03
to
This I answer this week to print sheets
Change printout to printpreview

I think you can use it

Add a userform to your workbook with one listbox and one button
in the properties of the listbox set multiselect to 1

Place this code in the userform module
when you open the userform the listbox have all the sheets in them
Select the sheets you want and press the button to print

Private Sub CommandButton1_Click()
Dim arr() As String
Dim N As Integer
N = 0
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
N = N + 1
ReDim Preserve arr(1 To N)
arr(N) = ListBox1.List(i)
End If
Next i
If N = 0 Then
MsgBox "You must select at least one Sheet"
Exit Sub
End If
ThisWorkbook.Worksheets(arr).PrintOut
End Sub

Private Sub UserForm_Initialize()
For Each ws In ActiveWorkbook.Sheets
If ws.Visible = True Then
Me.ListBox1.AddItem (ws.Name)
End If
Next
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Worksheets(1).Select
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl

"John Shikella" <shik...@hotmail.com> wrote in message news:5927a6a.03051...@posting.google.com...

kiat

unread,
May 15, 2003, 1:16:25 AM5/15/03
to
i recorded this macro for you which contains the glue to your question

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 15-05-2003 by kiat
'

'
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
ActiveWindow.SelectedSheets.PrintPreview
End Sub

hint: If something Then Worksheets("Home Deleivery").Select False


"John Shikella" <shik...@hotmail.com> wrote in message
news:5927a6a.03051...@posting.google.com...

0 new messages