I have a user form and one of the items is to show the print Preview for several sheets
when running the macro , I am able to to select "ClosePrint Preview"
However when running the macro via the user form" it freezes and I need to right click on the task bar for the workbook and select close window
It would be appreciated if someone could assist me so that the printview using the user form does not freeze and can select the or cancel button to exit
See User form code below
Private Sub CancelButton_Click()
Unload UserForm1
End Sub
Private Sub OKButton_Click()
Application.ScreenUpdating = False
If OptionprintPreview Then
PrintPreview_salesSheets
End If
End Sub
See macro below
Sub PrintPreview_SalesSheets()
Dim Sht As Worksheet, C As Range
Dim iRow As Long
For Each Sht In ThisWorkbook.Sheets 'loop through all sheets
With Sht
If .Name Like "sales*" Then 'check name
Set C = .Range("A1").CurrentRegion 'range around A1
.ResetAllPageBreaks
For iRow = C.Row + 25 To C.Row + C.Rows.Count + 1 Step 25
.Rows(iRow).PageBreak = xlPageBreakManual
Next
With .PageSetup
.PrintArea = C.Resize(, 21).Address
.CenterFooter = "&a &P of &N &D &T"
.Orientation = xlLandscape
.Zoom = 65 'Set Print Size to 80% of Full Size - otherwise 60 lines per page overflows
.FitToPagesWide = 1 'Put All Columns in the Print Area on One Sheet
.FitToPagesTall = 1 'Use as many Pages as necessary
.PrintGridlines = True
End With
.PrintPreview 'Print Preview
Application.SendKeys "{ESC}"
Application.Goto .Range("A1")
End If
End With
Next
End Sub
Bookmarks