I have the following code which loops through a list of worksheets, goes to those which have been selected, checks a checkbox which subsequently hides a few columns and rows and then prints out that sheet:
Problem is it prints before it has a chance to adjust the columns.
I tried adding in a wait:
But that pauses for 3 seconds as soon as a press the command button, no matter where in the code I put it.
Is there something I can do to get this working?
thanks for your help
Code:
Private Sub CommandButton1_Click() 'PRINT
Dim i As Long
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) = True Then
If Me.HeaderInc = 0 Then
Sheets(Me.ListBox1.List(i)).CheckBox1.Value = True
Else
Sheets(Me.ListBox1.List(i)).CheckBox1.Value = False
End If
Sheets(Me.ListBox1.List(i)).Rows("1:1").EntireRow.Hidden = True
Sheets(Me.ListBox1.List(i)).CheckBox6.Value = True
With Sheets(Me.ListBox1.List(i)).PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.Orientation = xlPortrait
.LeftFooter = "Printed on &D" ' Date
.CenterFooter = "Section: &A"
.RightFooter = "page &P of &N" ' page n of m
.PrintTitleRows = ActiveSheet.Rows(14).Address
End With
Sheets(Me.ListBox1.List(i)).PrintOut
Sheets(Me.ListBox1.List(i)).Rows("1:1").EntireRow.Hidden = False
Sheets(Me.ListBox1.List(i)).CheckBox6.Value = False
End If
Next i
Me.Hide
End Sub
Problem is it prints before it has a chance to adjust the columns.
I tried adding in a wait:
Code:
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
But that pauses for 3 seconds as soon as a press the command button, no matter where in the code I put it.
Is there something I can do to get this working?
thanks for your help