Hi I have the following code...
Private Sub CbnPrint_Click()
Dim i As Integer, j As Integer
Dim a() As Variant
On Error GoTo Errhandler
Application.ScreenUpdating = False
For i = 1 To Me.ListBox1.ListCount
If Me.ListBox1.Selected(i - 1) = True Then
j = j + 1
ReDim Preserve a(j)
a(j) = Worksheets(ListBox1.List(i - 1)).Name
End If
Next
*** Worksheets(a).PageSetup.FitToPagesWide = 1
Worksheets(a).Select
Me.Hide
Application.Dialogs(xlDialogPrint).Show
For i = 1 To Me.ListBox1.ListCount
If Me.ListBox1.Selected(i - 1) = True Then
Me.ListBox1.Selected(i - 1) = False
End If
Next
Errhandler:
Worksheets(1).Select
Application.ScreenUpdating = True
Exit Sub
End Sub
I want to set the FitToPagesWide = 1 for each of the selected worksheets. The above code doesn't work. Can anyone help?
Private Sub CbnPrint_Click()
Dim i As Integer, j As Integer
Dim a() As Variant
On Error GoTo Errhandler
Application.ScreenUpdating = False
For i = 1 To Me.ListBox1.ListCount
If Me.ListBox1.Selected(i - 1) = True Then
j = j + 1
ReDim Preserve a(j)
a(j) = Worksheets(ListBox1.List(i - 1)).Name
End If
Next
*** Worksheets(a).PageSetup.FitToPagesWide = 1
Worksheets(a).Select
Me.Hide
Application.Dialogs(xlDialogPrint).Show
For i = 1 To Me.ListBox1.ListCount
If Me.ListBox1.Selected(i - 1) = True Then
Me.ListBox1.Selected(i - 1) = False
End If
Next
Errhandler:
Worksheets(1).Select
Application.ScreenUpdating = True
Exit Sub
End Sub
I want to set the FitToPagesWide = 1 for each of the selected worksheets. The above code doesn't work. Can anyone help?