PC Review


Reply
Thread Tools Rate Thread

How to capture the Print button event

 
 
Newbie
Guest
Posts: n/a
 
      19th Oct 2007
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 With Quote
 
 
 
 
Otto Moehrbach
Guest
Posts: n/a
 
      19th Oct 2007
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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 With Quote
 
Newbie
Guest
Posts: n/a
 
      21st Oct 2007
Thanks a lot Otto!
That does help

"Otto Moehrbach" <(E-Mail Removed)> a écrit dans le message de news:
%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capture Print Event from a Report Preview Greg Microsoft Access Reports 1 15th May 2008 05:48 PM
How do I capture the button's click event of a DataGridView column? maarif@gmail.com Microsoft C# .NET 1 30th Apr 2008 02:58 PM
Capture Close Button Event John Microsoft Dot NET Framework Forms 3 29th Oct 2005 01:10 AM
capture right mouse button click event on cell Reinhard Thomann Microsoft Excel Programming 1 20th Jan 2005 12:28 PM
Can i capture print button click event on crystalreportview Joki Microsoft C# .NET 0 29th Nov 2004 11:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:00 PM.