Print preview

ManvinderKaur

Board Regular
Joined
Jun 16, 2010
Messages
149
Hi I am using following code for print preview of spreadsheet.

'command button to print site survey water worksheet
Private Sub cmdPrintSiteSurveyWater_Click()
On Error GoTo ErrorLine
Dim SiteSurveyWater As Integer
' message box to prompt print out
SiteSurveyWater = MsgBox("Do you want to take print out of Site Survey Water Sheet", vbYesNo + vbInformation, "Print Out")
If SiteSurveyWater = vbYes Then

With Worksheets("3.1 Site Survey Water Print")
.Visible = True
.Activate

With Worksheets("3.1 Site Survey Water Print").PageSetup

.PrintTitleRows = "$1:$3"
.PrintTitleColumns = ""
.PrintArea = "$A$1:$I$37"
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = "Page &P"
.CenterFooter = ""
.RightFooter = "&T &D"
.LeftMargin = Application.InchesToPoints(0.26)
.RightMargin = Application.InchesToPoints(0.26)
.TopMargin = Application.InchesToPoints(0.4)
.BottomMargin = Application.InchesToPoints(0.4)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.Zoom = 77

End With

.PrintPreview

End With
End If
Exit Sub
ErrorLine:
MsgBox ("Error Number:" & Err.Number & ". " & Err.Description & ". Source:" & Err.Source)
ActiveWorkbook.Close
End Sub


it is very slow... take 30 sec to display print preview....how come I modify this?...
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Do you need all that PageSetup code (which can be slow)? If all those properties have already been set there is no point in setting them again.
 
Upvote 0
okay thanks....the opened spreadsheet becomes visible..once the public see print preview...Is this possible ?...if they see print preview and then take print out and then that sheet again becomes hidden?....is it?.....I can not figure that out...
 
Upvote 0
Try:

Code:
Private Sub cmdPrintSiteSurveyWater_Click_Click()
    On Error GoTo ErrorLine
    Dim SiteSurveyWater As VbMsgBoxResult
'   Message box to prompt print out
    SiteSurveyWater = MsgBox("Do you want to take print out of Site Survey Water Sheet", vbYesNo + vbQuestion, "Print Out")
    If SiteSurveyWater = vbYes Then
        With Worksheets("3.1 Site Survey Water Print")
            .Visible = True
            .PrintPreview
            .Visible = False
        End With
    End If
    Exit Sub
ErrorLine:
    MsgBox ("Error Number:" & Err.Number & ". " & Err.Description & ". Source:" & Err.Source)
    ActiveWorkbook.Close
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top