Problem with Beforeprint and Workbook.Printout function

K

KP

I have a interface that allows the user to print the entire workbook
without viewing it. A form is used to create a workbook based on what
selections are in the listbox (1 to Many). Excel Opens, prints and
closes quickly which is fine. See printing code:

If frmName.ckPrint.Value = True Then
ActiveWorkBook.PrintOut 1 'Print entire workbook
End If
If frmName.ckView.Value = False Then
wkbName.Close False 'Then close workbook.
End If

If the user wants to veiw the workbook (ckview = true) and it's on
their desktop until they save it or close it. Should they want to
print the workbook once it's opened the Workbook_BeforePrint routine
runs. This routine adds a Header to some sheets and Prints the
Entireworkbook. See code:

***************************************************************
Dim oSheet As Object

Application.EnableEvents = False
Application.ScreenUpdating = False

'Set Header
For Each oSheet In ThisWorkbook.Sheets
If oSheet.Index <> 1 Then
oSheet.Unprotect
oSheet.PageSetup.LeftHeader = Range("HeaderName").Value
oSheet.Protect
End If
Next
ActiveWorkbook.PrintOut
Application.EnableEvents = True

'Prevents the active sheet from printing again.
Cancel = True

Application.ScreenUpdating = True

***************************************************************

This code works fine in the activeworkbook by itself, however they
seem to cancel each other out when trying to Print via the Userform
which is in another workbook. (The UserForm recognizes the workbook
it should be printing by knowing it's Name (Activeworkbook.Name)

ActiveWorkBook.PrintOut 1

then proceeds to the Workbook_BeforePrint sub routine, continues
through the code but nothing gets printed. Can anyone help in trying
to solve this problem?
 
Top