printpreview

A

Alex

I'm using the following code to prevent the empty rows printing.
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Initiatives" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
On Error Resume Next
.Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden =
True
.PrintOut
.Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden =
False
On Error GoTo 0
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
But, when I'm trying to use the code below to get a preprint report it's not
working.
ActiveWindow.SelectedSheets.PrintPreview

Could anybody advise how I could make it's working?

Thanks
 
R

Ron de Bruin

Hi Alex

Try to disable the events

Application.EnableEvents = False
ActiveWindow.SelectedSheets.PrintPreview
Application.EnableEvents = True
 
A

Alex

Thanks a lot, Ron.
Now, it's working.

Ron de Bruin said:
Hi Alex

Try to disable the events

Application.EnableEvents = False
ActiveWindow.SelectedSheets.PrintPreview
Application.EnableEvents = True
 
A

Alex

Sorry, Ron.
I've reported it as done. But, now I'm getting all pages not just filled
rows as before.
The Private Sub Workbook_BeforePrint(Cancel As Boolean) is not working.
(the code in the post below )
 
R

Ron de Bruin

I've reported it as done. But, now I'm getting all pages not just filled
rows as before.

That's correct
What did you expect

If you only want to preview then use

Sub test()
With Sheets("Initiatives")
On Error Resume Next
.Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.PrintPreview
.Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = False
On Error GoTo 0
End With
End Sub
 
A

Alex

Thank you very much. It's working

Ron de Bruin said:
That's correct
What did you expect

If you only want to preview then use

Sub test()
With Sheets("Initiatives")
On Error Resume Next
.Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
.PrintPreview
.Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = False
On Error GoTo 0
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top