Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to capture the Print button event

Hello,
I created an application with several sheets:
- Sheet1 is a form with a lot of dropdown lists.
- Sheet2, named "Impression", is the document to be printed with all the
values selected in Sheet1
Sheet 2 is hidden

What I want to do is to capture the Print event, so that the VBA macro print
the document in Sheet2, but nothing else. In fact, my macro prints both
sheets...

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Impression").PageSetup.PrintArea = "$A$1:$H$49"
Worksheets("Impression").PrintOut Copies:=1, Collate:=True
Cancel = False
End Sub

If I set Cancel = True, nothing is printed !

How can I do that ?
Thanks for your help.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default How to capture the Print button event

Be very specific when you say "Print button". There are various ways to
initiate printing and you can get different results from each. Exactly what
are you doing to initiate printing? What are the current print settings
when you do what you do?
The easiest way to convert any print initiation to print only from your code
is to first cancel the print command. You do this by setting Cancel to True
in the first line of your macro. By so doing you are using the print
command to fire the macro and to do nothing else. The remaining code in
your macro will then be executed. You might find that you can't print from
a hidden sheet so you may have to include code to unhide/re-hide the sheet.
Another problem is that the print command in your code will fire the
very macro that holds your code. You don't want this to happen, so bracket
your code with the following two lines:
Application.EnableEvents=False
'Your print code
Application.EnableEvents=True
HTH Otto
"Newbie" wrote in message
...
Hello,
I created an application with several sheets:
- Sheet1 is a form with a lot of dropdown lists.
- Sheet2, named "Impression", is the document to be printed with all the
values selected in Sheet1
Sheet 2 is hidden

What I want to do is to capture the Print event, so that the VBA macro
print the document in Sheet2, but nothing else. In fact, my macro prints
both sheets...

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Impression").PageSetup.PrintArea = "$A$1:$H$49"
Worksheets("Impression").PrintOut Copies:=1, Collate:=True
Cancel = False
End Sub

If I set Cancel = True, nothing is printed !

How can I do that ?
Thanks for your help.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to capture the Print button event

Thanks a lot Otto!
That does help

"Otto Moehrbach" a écrit dans le message de news:
...
Be very specific when you say "Print button". There are various ways to
initiate printing and you can get different results from each. Exactly
what are you doing to initiate printing? What are the current print
settings when you do what you do?
The easiest way to convert any print initiation to print only from your
code is to first cancel the print command. You do this by setting Cancel
to True in the first line of your macro. By so doing you are using the
print command to fire the macro and to do nothing else. The remaining
code in your macro will then be executed. You might find that you can't
print from a hidden sheet so you may have to include code to
unhide/re-hide the sheet.
Another problem is that the print command in your code will fire the
very macro that holds your code. You don't want this to happen, so
bracket your code with the following two lines:
Application.EnableEvents=False
'Your print code
Application.EnableEvents=True
HTH Otto
"Newbie" wrote in message
...
Hello,
I created an application with several sheets:
- Sheet1 is a form with a lot of dropdown lists.
- Sheet2, named "Impression", is the document to be printed with all the
values selected in Sheet1
Sheet 2 is hidden

What I want to do is to capture the Print event, so that the VBA macro
print the document in Sheet2, but nothing else. In fact, my macro prints
both sheets...

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Worksheets("Impression").PageSetup.PrintArea = "$A$1:$H$49"
Worksheets("Impression").PrintOut Copies:=1, Collate:=True
Cancel = False
End Sub

If I set Cancel = True, nothing is printed !

How can I do that ?
Thanks for your help.






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
capture link update event xk Excel Programming 0 December 9th 06 06:10 PM
Stop Capture Event OverAC[_19_] Excel Programming 4 April 11th 06 02:08 PM
Any way to capture an Autofilter event? mrwaller Excel Programming 1 January 20th 06 06:15 PM
capture right mouse button click event on cell Reinhard Thomann Excel Programming 0 January 20th 05 11:41 AM
Capture scrolling event Allen[_12_] Excel Programming 2 April 22nd 04 03:37 AM


All times are GMT +1. The time now is 10:28 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"