PrintOut & xlDialogPrint skipped

ChgsAllAround

New Member
Joined
Apr 11, 2008
Messages
36
I have a workbook that by default shows 1 sheet where the user makes selections from a listbox. Once the selections are made, new sheets are created for each of them in this workbook. I have created a button that should both create and print by clicking on it. The code for this is:

Code:
Sub Picture26_Click() 'print
    Worksheets.Add().Name = "Sample"
    Application.Dialogs(xlDialogPrint).Show
End Sub

This works fine until I want to add something for "after" printing. As soon as I create a sub for Workbook_BeforePrint, anything I put in it related to printing is treated as though it doesn't exist, ie, doesn't do that line, but does everything else in the sub. Here is a sample of code for that:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Application.EnableEvents = False
    Cancel = True
    'select all visible worksheets
    For Each ws In Worksheets
        If ws.Visible = True Then ws.Select (False)
    Next
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    MsgBox ("should have printed")
    Application.EnableEvents = True
End Sub

Nothing prints. If I change the PrintOut statement to show the dialog box, I don't get the dialog box.

Why?
Thanks!
Mari
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Thanks, Gary.
Removing Cancel works for the actual button, but if you select File > Print, it prints, THEN brings up the print dialog box. I think I need another solution or an addition.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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