Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Triggering a macro after Printing

Below is some code I am working on. Basically it looks at specific cell A7.
If it is equal to zero then that row gets hidden when printing. I want all
rows to unhide after printing. How do I trigger this? The section under
Before_Save is what I would like to do after printing. Is there an easier
way to do this?



Private Sub Workbook_BeforePrint(Cancel As Boolean)
Sheets("January").Select
If Cells(7, 1) = 0 Then
Rows("7:7").EntireRow.Hidden = True
End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets(Array("January", "February", "March", "April", _
"May", "June", "July", "August", "September", _
"October", "November", "December", "Summary")).Select
Cells.Select
Selection.EntireRow.Hidden = False
Sheets("January").Select
Cells(1, 1).Select
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Triggering a macro after Printing

Thanks for the help. Here is what I got. I removed the "On Error" because I
am still debugging this (I made another macro to enable the events back on).
This code seems to be working okay. But I would prefer to have the print
window when printing. The "PrintOut" command skips that and prints it
immediately to the default printer. So now I can't cancel or even perform a
print preview.

Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim wkSht As Worksheet
Sheets(Array("January", "February", "March", "April", _
"May", "June", "July", "August", "September", "October", _
"November", "December", "Summary")).Select
For Each wkSht In ActiveWindow.SelectedSheets
If wkSht.Cells(7, 1) = 0 Then
wkSht.Rows("7:7").EntireRow.Hidden = True
End If
Next wkSht

Cancel = True

Application.EnableEvents = False
ActiveWindow.SelectedSheets.PrintOut
Application.EnableEvents = True

For Each wkSht In ActiveWindow.SelectedSheets
wkSht.Cells.EntireRow.Hidden = False
Next wkSht
Cells(1, 1).Select
Sheets("January").Select

End Sub


"Jim Thomlinson" wrote:

This should be close...

Private Sub Workbook_BeforePrint(Cancel As Boolean)
On Error GoTo ErrorHandler
Application.EnableEvents = False
Cancel = True
Sheets("January").Select
If Cells(7, 1) = 0 Then
Rows("7:7").EntireRow.Hidden = True
End If
ActiveSheet.PrintOut
DoStuff
ErrorHandler:
Application.EnableEvents = True
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
DoStuff
End Sub

Private Sub DoStuff()
Sheets(Array("January", "February", "March", "April", _
"May", "June", "July", "August", "September", _
"October", "November", "December", "Summary")).Select
Cells.Select
Selection.EntireRow.Hidden = False
Sheets("January").Select
Cells(1, 1).Select
End Sub
--
HTH...

Jim Thomlinson


"Sloth" wrote:

Below is some code I am working on. Basically it looks at specific cell A7.
If it is equal to zero then that row gets hidden when printing. I want all
rows to unhide after printing. How do I trigger this? The section under
Before_Save is what I would like to do after printing. Is there an easier
way to do this?



Private Sub Workbook_BeforePrint(Cancel As Boolean)
Sheets("January").Select
If Cells(7, 1) = 0 Then
Rows("7:7").EntireRow.Hidden = True
End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets(Array("January", "February", "March", "April", _
"May", "June", "July", "August", "September", _
"October", "November", "December", "Summary")).Select
Cells.Select
Selection.EntireRow.Hidden = False
Sheets("January").Select
Cells(1, 1).Select
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Triggering a macro after Printing

I changed PrintOut to PrintPreview. This always takes me to the printpreview
screen but then the print button (in the preview screen) works normally.
That's seems wierd to me, but it works. Is there any danger to doing it like
this?

Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim wkSht As Worksheet
Sheets(Array("January", "February", "March", "April", _
"May", "June", "July", "August", "September", _
"October", "November", "December", "Summary")).Select
For Each wkSht In ActiveWindow.SelectedSheets
If wkSht.Cells(7, 1) = 0 Then
wkSht.Rows("7:7").EntireRow.Hidden = True
End If
Next wkSht

Cancel = True

Application.EnableEvents = False
ActiveWindow.SelectedSheets.PrintPreview
Application.EnableEvents = True

For Each wkSht In ActiveWindow.SelectedSheets
wkSht.Cells.EntireRow.Hidden = False
Next wkSht
Cells(1, 1).Select
Sheets("January").Select

End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Triggering a macro after Printing

Roedd <<Sloth wedi ysgrifennu:

Below is some code I am working on. Basically it looks at specific
cell A7. If it is equal to zero then that row gets hidden when
printing. I want all rows to unhide after printing. How do I
trigger this? The section under Before_Save is what I would like to
do after printing. Is there an easier way to do this?


http://www33.brinkster.com/rbad/defa...page=newevents

--
Rob

Original portions of his message are
copyright Robert Bruce and intended
for distribution only via NNTP.
Dissemination via third party Web forums with the
exception of Google Groups and Microsoft Communities
is strictly prohibited and may result in legal action.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default Triggering a macro after Printing

Thank you so much!!!! That's perfect.

"Robert Bruce" wrote:

Roedd <<Sloth wedi ysgrifennu:

Below is some code I am working on. Basically it looks at specific
cell A7. If it is equal to zero then that row gets hidden when
printing. I want all rows to unhide after printing. How do I
trigger this? The section under Before_Save is what I would like to
do after printing. Is there an easier way to do this?


http://www33.brinkster.com/rbad/defa...page=newevents

--
Rob

Original portions of his message are
copyright Robert Bruce and intended
for distribution only via NNTP.
Dissemination via third party Web forums with the
exception of Google Groups and Microsoft Communities
is strictly prohibited and may result in legal action.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Triggering a macro after Printing

Sheets(Array("January", "February", "March", "April", _
"May", "June", "July", "August", "September", _
"October", "November", "December", "Summary")).Select

As a side note... Just an alternative if you prefer:

Sheets(Application.GetCustomListContents(4)).Selec t
Sheets("Summary").Select False ' Don't Replace

Also, depending on what you are doing...
Rows("7:7").EntireRow.Hidden = (Cells(7, 1) = 0)

--
HTH. :)
Dana DeLouis
Windows XP, Office 2003


"Sloth" wrote in message
...
I changed PrintOut to PrintPreview. This always takes me to the
printpreview
screen but then the print button (in the preview screen) works normally.
That's seems wierd to me, but it works. Is there any danger to doing it
like
this?

Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim wkSht As Worksheet
Sheets(Array("January", "February", "March", "April", _
"May", "June", "July", "August", "September", _
"October", "November", "December", "Summary")).Select
For Each wkSht In ActiveWindow.SelectedSheets
If wkSht.Cells(7, 1) = 0 Then
wkSht.Rows("7:7").EntireRow.Hidden = True
End If
Next wkSht

Cancel = True

Application.EnableEvents = False
ActiveWindow.SelectedSheets.PrintPreview
Application.EnableEvents = True

For Each wkSht In ActiveWindow.SelectedSheets
wkSht.Cells.EntireRow.Hidden = False
Next wkSht
Cells(1, 1).Select
Sheets("January").Select

End Sub



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
Triggering a macro after Printing Jim Thomlinson[_5_] Excel Programming 0 February 6th 06 09:33 PM
Function triggering a macro Leon Excel Worksheet Functions 1 December 22nd 05 07:26 AM
Daily Macro Triggering JB2010 Excel Discussion (Misc queries) 2 November 2nd 05 04:28 PM
Triggering Excel Macro from MS-Project Buster Excel Programming 2 November 20th 04 11:35 AM
Triggering Macro Execution Peter M[_3_] Excel Programming 1 January 12th 04 08:20 PM


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