having trouble with Workbook_BeforePrint(Cancel as Boolean)


Posted by Blake on February 14, 2002 7:05 AM

Workbook_BeforePrint initiates a userform that appears, the macro works fine unless it is invoked by print preview where it will then lock up to a point that I need to give it the three finger salute. Is there anyway to know if printpreview is the initiator of the macro? or does anyone know why this may be happening?

Posted by JohnG on February 14, 2002 7:16 AM

Not sure what your problem is as I do not know what code you are using. But I can tell you that the before_print code is called twice when the print preview is used, once to view the preview the second when you choose to print. I used this to confirm.
Sub Workbook_BeforePrint(Cancel As Boolean)
MsgBox "Would print at this point."
End Sub

Posted by blake on February 14, 2002 7:35 AM

Private Sub Workbook_beforeprint(Cancel As Boolean)
If worksheetname = "" Then
Cancel = True
Application.Run ("printer1")
End If
End Sub

sub printer1()
'goes through a bunch of if statements
'then diplays a form with a print button
'and a cancel button
'but throughout the whole macro Cancel=False
'so in the print button is the Print command
'and the cancel button just closes the form
end sub

ANY IDEAS?????


end sub

Posted by blake on February 14, 2002 7:38 AM

what i wanted to happen was if print preview is chosen then you view print preview normally and then if you chose to print it after that the form would appear, any help is appreciated. Not sure what your problem is as I do not know what code you are using. But I can tell you that the before_print code is called twice when the print preview is used, once to view the preview the second when you choose to print. I used this to confirm.



Posted by JohnG on February 14, 2002 8:39 AM

The problem seems to be issolating which button (print or print preview) was clicked. Havent found away to determine this yet. Private Sub Workbook_beforeprint(Cancel As Boolean)

end sub : Not sure what your problem is as I do not know what code you are using. But I can tell you that the before_print code is called twice when the print preview is used, once to view the preview the second when you choose to print. I used this to confirm. : Sub Workbook_BeforePrint(Cancel As Boolean) : MsgBox "Would print at this point." : End Sub :