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:
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:
Nothing prints. If I change the PrintOut statement to show the dialog box, I don't get the dialog box.
Why?
Thanks!
Mari
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