Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Problem - Workbook_BeforePrint

HELLO VB EXPERTS,

It seems that Workbook_BeforePrint event is triggered by both PrintOut and
PrintPreview. Is it possible that I could run a different code for each of
the command the user will choose. somewhat like:

Private Sub Workbook_BeforePrint

If user choose PrintOut Then
My code goes here
Else
My other code goes here
End If

End Sub

Anyone who could give light to my problem will be highly appreciated

Thanks in advance,

Jon-jon





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Problem - Workbook_BeforePrint

You could use a more elaborate form but this should get you started. Place
the code in the "ThisWorkbook" module

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
Dim Msg As String, Style As String, Title As String
Dim Response As String, MyAnswer As String
Msg = "Select 'Yes' to Print, 'No' to Print Preview, 'Cancel' to exit"
Style = vbYesNoCancel + vbQuestion
Title = "Print or Print Preview"
Response = MsgBox(Msg, Style, Title)
Application.EnableEvents = False
If Response = vbYes Then
MyAnswer = "No printing allowed"
'or other code for a macro here
ElseIf Response = vbNo Then
MyAnswer = "Print Preview allowed"
'or other code for a macro here
ActiveSheet.PrintPreview
ElseIf Response = vbCancel Then
MyAnswer = "Bailing out"
End If
Application.EnableEvents = True
MsgBox MyAnswer
End Sub


--
XL2002
Regards

William


"JON-JON" wrote in message
...
| HELLO VB EXPERTS,
|
| It seems that Workbook_BeforePrint event is triggered by both PrintOut and
| PrintPreview. Is it possible that I could run a different code for each
of
| the command the user will choose. somewhat like:
|
| Private Sub Workbook_BeforePrint
|
| If user choose PrintOut Then
| My code goes here
| Else
| My other code goes here
| End If
|
| End Sub
|
| Anyone who could give light to my problem will be highly appreciated
|
| Thanks in advance,
|
| Jon-jon
|
|
|
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problem - Workbook_BeforePrint

It does trigger an event, but William turned off events. The problem is,
that when his code issues the printout or printpreview command, the event
will be fired again unless he turns off events.

--
Regards,
Tom Ogilvy



"JON-JON" wrote in message
...
William,

Thank you very much!
However, there is one more big problem. After allowing the printpreview,
there is a commandbutton [print...] in the preview window and clicking it
doesn't trigger the BeforePrint event anymore and so in effect the code
becomes useless.
Is there a way a can solve this? One more interesting question, does
Microsoft doesn't come to think of it that said commandbutton should also
trigger an event?

Hope to received more replies from you and other VB experts out there.

Jon-jon

"William" wrote in message
...
You could use a more elaborate form but this should get you started.

Place
the code in the "ThisWorkbook" module

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
Dim Msg As String, Style As String, Title As String
Dim Response As String, MyAnswer As String
Msg = "Select 'Yes' to Print, 'No' to Print Preview, 'Cancel' to exit"
Style = vbYesNoCancel + vbQuestion
Title = "Print or Print Preview"
Response = MsgBox(Msg, Style, Title)
Application.EnableEvents = False
If Response = vbYes Then
MyAnswer = "No printing allowed"
'or other code for a macro here
ElseIf Response = vbNo Then
MyAnswer = "Print Preview allowed"
'or other code for a macro here
ActiveSheet.PrintPreview
ElseIf Response = vbCancel Then
MyAnswer = "Bailing out"
End If
Application.EnableEvents = True
MsgBox MyAnswer
End Sub


--
XL2002
Regards

William


"JON-JON" wrote in message
...
| HELLO VB EXPERTS,
|
| It seems that Workbook_BeforePrint event is triggered by both PrintOut

and
| PrintPreview. Is it possible that I could run a different code for

each
of
| the command the user will choose. somewhat like:
|
| Private Sub Workbook_BeforePrint
|
| If user choose PrintOut Then
| My code goes here
| Else
| My other code goes here
| End If
|
| End Sub
|
| Anyone who could give light to my problem will be highly appreciated
|
| Thanks in advance,
|
| Jon-jon
|
|
|
|
|






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Problem - Workbook_BeforePrint

Tom,
I got your point and thanks for clearing it up to me. (Almost blame
Microsoft for my own ignorance, sorry!)
This brings me back to my original problem that is knowing if the user
initially choose a printpreview command or a printout.

Somewhat like

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If user initially choose printpreview then
my code goes here
Else
my other code goes here
End if
End sub

I find it logical but I really don't think it is possible or not.

Thanks,

Jon-jon




"Tom Ogilvy" wrote in message
...
It does trigger an event, but William turned off events. The problem is,
that when his code issues the printout or printpreview command, the event
will be fired again unless he turns off events.

--
Regards,
Tom Ogilvy



"JON-JON" wrote in message
...
William,

Thank you very much!
However, there is one more big problem. After allowing the

printpreview,
there is a commandbutton [print...] in the preview window and clicking

it
doesn't trigger the BeforePrint event anymore and so in effect the code
becomes useless.
Is there a way a can solve this? One more interesting question, does
Microsoft doesn't come to think of it that said commandbutton should

also
trigger an event?

Hope to received more replies from you and other VB experts out there.

Jon-jon

"William" wrote in message
...
You could use a more elaborate form but this should get you started.

Place
the code in the "ThisWorkbook" module

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
Dim Msg As String, Style As String, Title As String
Dim Response As String, MyAnswer As String
Msg = "Select 'Yes' to Print, 'No' to Print Preview, 'Cancel' to exit"
Style = vbYesNoCancel + vbQuestion
Title = "Print or Print Preview"
Response = MsgBox(Msg, Style, Title)
Application.EnableEvents = False
If Response = vbYes Then
MyAnswer = "No printing allowed"
'or other code for a macro here
ElseIf Response = vbNo Then
MyAnswer = "Print Preview allowed"
'or other code for a macro here
ActiveSheet.PrintPreview
ElseIf Response = vbCancel Then
MyAnswer = "Bailing out"
End If
Application.EnableEvents = True
MsgBox MyAnswer
End Sub


--
XL2002
Regards

William


"JON-JON" wrote in message
...
| HELLO VB EXPERTS,
|
| It seems that Workbook_BeforePrint event is triggered by both

PrintOut
and
| PrintPreview. Is it possible that I could run a different code for

each
of
| the command the user will choose. somewhat like:
|
| Private Sub Workbook_BeforePrint
|
| If user choose PrintOut Then
| My code goes here
| Else
| My other code goes here
| End If
|
| End Sub
|
| Anyone who could give light to my problem will be highly appreciated
|
| Thanks in advance,
|
| Jon-jon
|
|
|
|
|








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
problem with a conditional max problem Brian Cornejo Excel Discussion (Misc queries) 1 February 18th 05 06:25 PM


All times are GMT +1. The time now is 01:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"