View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default worksheet grouping, Sheets(Array... property

Maybe something like:

Option Explicit
Private Sub CommandButton1_Click()
Dim iCtr As Long
Dim myArr() As String
Dim SelectedCount As Long

'an array that will hold all the sheet names
ReDim myArr(1 To Me.ListBox1.ListCount)

SelectedCount = 0
For iCtr = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(iCtr) Then
SelectedCount = SelectedCount + 1
myArr(SelectedCount) = Me.ListBox1.List(iCtr)
End If
Next iCtr

If SelectedCount = 0 Then
'do nothing
Else
'just use the part that we used--kill the rest
ReDim Preserve myArr(1 To SelectedCount)
Me.Hide 'for preview:=true
Sheets(myArr).PrintOut preview:=True
'commented out
'Copies:=NumberCopy.Text, Collate:=True
Me.Show
End If

End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim sht As Object
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
For Each sht In ActiveWorkbook.Sheets
.AddItem sht.Name
Next sht
End With

End Sub


wrote:

I have the following bit of code that J-walk.com graciously makes
available on its batch printer tool:

' Begin routine
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
With Sheets(ListBox1.List(i))
.PrintOut Copies:=NumberCopy.Text, Collate:=True
End With
End If
Next i

This works great if you want individual printouts, but I would like to
modify it to group the selected worksheets and then print as one job
(so that auto page numbers will be sequential). I believe I need to
use the Sheets(Array(... property with the .Select property prior to
the .PrintOut property, but I cannot figure out how to arrange it after
many attempts. I am very much a newbie when it comes to VBA. Any help
is appreciated and thank you in advance.

xl2003
winxppro


--

Dave Peterson