Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
capture link update event | Excel Programming | |||
Stop Capture Event | Excel Programming | |||
Any way to capture an Autofilter event? | Excel Programming | |||
capture right mouse button click event on cell | Excel Programming | |||
Capture scrolling event | Excel Programming |