PDA

View Full Version : Excel 2013 Print Preview Code



zoom38
05-25-2017, 08:25 AM
Good morning, below is code that one of the guru's helped me with a while back. The code works great in excel 2010 but it does not seem to work properly in excel 2013. The idea is for the code to take the following sheets "IAP Cover", "202", "203", "205", "206", "208" and put them into print preview where the user can print or cancel printing. The code also counts the "204" sheets because there may be more than one of them.

The problem in excel 2013 is that on the print preview screen, only the first sheet is visible "IAP Cover". When you press next page the "IAP Cover" remains visible. However the correct number of pages show and the correct sheets printout when print is selected.

Anyone have an idea how to update the code for print preview to work correctly in excel 2013?

Thanks
Gary



Sub PrintBasicIAP()
'Opens up the sheets in print preview. You may cancel or print from the print preview screen.

Dim ppWorksheets()
Dim count As Long
Dim ws As Worksheet
Dim dummy As String

Application.EnableEvents = False
Application.ScreenUpdating = False
UserForm1.Hide

ppWorksheets = Array("IAP Cover", "202", "203", "205", "206", "208")
count = UBound(ppWorksheets)
For Each ws In ThisWorkbook.Worksheets
If StrComp(Left(ws.Name, 3), "204", vbTextCompare) = 0 Then
count = count + 1
ReDim Preserve ppWorksheets(count)
ppWorksheets(UBound(ppWorksheets)) = ws.Name
End If
Next ws

Sheets(ppWorksheets).PrintPreview
Sheets("Print IAP").Select

Call ShowUserform1(dummy)

Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

zoom38
05-25-2017, 08:41 AM
Interesting, if I click "next page" the first sheet is still visible. If I then click zoom, the correct page will now be visible. This works for all the pages, after clicking "next page" or "previous page" and the zoom, the appropriate page will be visible. Is this a flaw in excel 2013?