Thread: Page Selection
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default Page Selection

Another suggestion (based on one of your previous posts is to build that array
of worksheet names and then use that:

Option Explicit
Private Sub UserForm_Initialize()
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
Me.ListBox1.AddItem wks.Name
Next wks

Me.ListBox1.MultiSelect = fmMultiSelectMulti
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()

Dim Result() As String
Dim i As Long
Dim j As Long

ReDim Preserve Result(0 To Me.ListBox1.ListCount - 1)

j = -1
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
j = j + 1
Result(j) = ListBox1.List(i)
End If
Next i

If j = -1 Then
'do nothing, nothing selected
Else
ReDim Preserve Result(0 To j)
ActiveWorkbook.Worksheets(Result).PrintOut
End If

Unload Me

End Sub




Sagaron wrote:

Brilliant - I can understand what you mean by tricky - thanks for your
help!

--
Sagaron
------------------------------------------------------------------------
Sagaron's Profile: http://www.excelforum.com/member.php...o&userid=24643
View this thread: http://www.excelforum.com/showthread...hreadid=382314


--

Dave Peterson