Can print preview action be disabled

DRJ

MrExcel MVP
Joined
Feb 17, 2002
Messages
3,853
I am having a little trouble with a userform. When I press print the userform comes up and I can select what sheets to print out. No problem here, but if I press print preview and select a page to print it will go to the print preview screen, but if I do not select anything or press the cancel button to just uinload the form excel gets hung up. Maybe becauase there is nothing to show in the print preview?

Anyways is there a simple way to just cancel the print if print preview was pressed. I don't want to disable any of the menu bar items or anything like that, I was just wondering if the before print event can determine if print was pressed or print preview? Or if anyone knows what the problem might be?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I dont think so, when I run that it just goes to the print preview screen. What I do now is just disable the print preview buttons from the tool bars and that should work. I was just wondering if there was a way for the before print event to tell if there was a print command or a print preview command. thanks for the help tho.

something like

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

    If Me.PrintPreview = True Then
        Cancel = True
        Else
        Cancel = True
        PrintFrm.Show
    End If

End Sub
 
Upvote 0
will this help:


Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
MsgBox "Preview and Print not allowed.", vbCritical, "PRINT DISABLED"
End Sub


but then this will disable printing as well including print preview.

Best Regards,

Shan
 
Upvote 0
Ponsy - Thanks for the link

Just Shan - unfortunately that will not work. What I have is before print it will cancel = true and show the userform. But if print preview is selected and then the userform is closed excel goes nuts. The link the Pansy posted suggests that this is just a problem with excel.

What I do now is just disable the print preview buttons, which works for my needs.

Thanks
 
Upvote 0
In a standard module:

Sub DisablePrintPreview()
Dim X As CommandBar, Z As CommandBarControl
For Each X In CommandBars
Set Z = X.FindControl(ID:=109, recursive:=True)
If Not Z Is Nothing Then Z.OnAction = "Test1" 'Set Z.OnAction = "" to re-enable
Next X
Set X = Nothing
Set Z = Nothing
End Sub

Sub Test1()
MsgBox "Print Preview is disabled."
End Sub


To re-enable PrintPreview, Set Z.OnAction = ""
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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