Workbook_BeforePrint macro

O

Otto Moehrbach

Excel XP & Win XP
When I click on File - Print Preview the Workbook_BeforePrint macro I have
fires. How can I have it not fire or what code can I put in the macro to
prevent execution of the rest of the code? Thanks for your time. Otto
 
B

Barb Reinhardt

When you print preview, the entire macro will be run. If you don't want
something to run, either delete it or move it to another module where you'll
use it.
 
O

Otto Moehrbach

Barb
I want the entire macro (it calls another macro) to run when the user
issues a print command. I take it then, from what you say, that there is no
way to detect that a Print Preview was commanded. Is that right? Thanks
for your time. Otto
 
B

Barb Reinhardt

I'm not aware of it, but I've just recently started working with event driven
macros.
 
J

Jim Cone

Hi Otto,
I tried writing some code and crashed Excel.
Here are some other ways to possible do it ...
http://snipurl.com/13du9
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Otto Moehrbach"
<[email protected]>
wrote in message
Excel XP & Win XP
When I click on File - Print Preview the Workbook_BeforePrint macro I have
fires. How can I have it not fire or what code can I put in the macro to
prevent execution of the rest of the code? Thanks for your time. Otto
 
J

J@@

Hi Otto
I'm not too fluent in VBA (nor in english) but I had similar trouble i fixed
that way, thanks to code from Leo Heuser :

In TWK :
Private Sub Workbook_Open()
RedefinePrintPreview 'voir proc dans module1 de ce fichier
End Sub

And in a std module :
'=========dans un module standard
Public Preview As Boolean

Sub RedefinePrintPreview()
'(e-mail address removed), May 2001
Dim CBar As CommandBar
Dim Found As CommandBarControl

For Each CBar In CommandBars
Set Found = CBar.FindControl(ID:=109, recursive:=True)
If Not Found Is Nothing Then
Found.OnAction = "Pre" ' Found.OnAction = "" for default

End If
Next CBar

Preview = False 'Not necessary but informative :)

End Sub

Sub Pre()
Preview = True
ActiveSheet.PrintPreview
Preview = False
End Sub
'===========================
'===============
Sub ResetPrintPreview()
Dim CBar As CommandBar
Dim Found As CommandBarControl

For Each CBar In CommandBars
Set Found = CBar.FindControl(ID:=109, recursive:=True)
If Not Found Is Nothing Then
Found.OnAction = "" 'pour avoir le fonctt par défaut
End If
Next CBar

End Sub
'===========================

HTH
J@@
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top