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

HI,

I am trying to develop some VBA code in excel 2003 that will
automatically place a specific header and footer on any sheet I print
from excel.

So far I have created the following code in my personal workbook.

Public Sub App_WorkbookBeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.RightFooter = "&D &T"
ActiveSheet.PageSetup.CenterFooter = "&F"
End Sub

It appears to work for that workbook but not others I have open.

Can anyone suggest how I can make this code apply to the excel
application instead of to a particular workbook?

Thanks,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default BeforePrint Event

Woody,
Application events. Then check if it is workbook that you wish to process.

http://www.cpearson.com/excel/AppEvent.htm

NickHK

"Woody" wrote in message
ups.com...
HI,

I am trying to develop some VBA code in excel 2003 that will
automatically place a specific header and footer on any sheet I print
from excel.

So far I have created the following code in my personal workbook.

Public Sub App_WorkbookBeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.RightFooter = "&D &T"
ActiveSheet.PageSetup.CenterFooter = "&F"
End Sub

It appears to work for that workbook but not others I have open.

Can anyone suggest how I can make this code apply to the excel
application instead of to a particular workbook?

Thanks,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default BeforePrint Event

Woody,

You need application events, and you need to invoke them from a workbook
that is opened whenever Excel is started. An obvious place is Personal.xls.
Add this code

Public WithEvents App As Application

Private Sub Workbook_Open()
Set App = Application
End Sub

Private Sub App_WorkbookBeforePrint(ByVal Wb As Workbook, Cancel As Boolean)
With Wb.ActiveSheet.PageSetup
.RightFooter = "&D &T"
.CenterFooter = "&F"
End With
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--
HTH

Bob Phillips

"Woody" wrote in message
ups.com...
HI,

I am trying to develop some VBA code in excel 2003 that will
automatically place a specific header and footer on any sheet I print
from excel.

So far I have created the following code in my personal workbook.

Public Sub App_WorkbookBeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.RightFooter = "&D &T"
ActiveSheet.PageSetup.CenterFooter = "&F"
End Sub

It appears to work for that workbook but not others I have open.

Can anyone suggest how I can make this code apply to the excel
application instead of to a particular workbook?

Thanks,



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
BeforePrint macro Steve O Excel Discussion (Misc queries) 4 September 21st 05 01:09 AM
BeforePrint Add In Daniel McCollick[_2_] Excel Programming 10 June 10th 05 08:07 PM
ADO 2.7 & ADO 2.8 beforeprint JCanyoneer Excel Programming 7 March 30th 05 04:05 PM
BeforePrint event EnglishTeacher Excel Programming 4 October 13th 04 04:17 PM
Help with BeforePrint Eric[_7_] Excel Programming 2 October 9th 03 07:44 PM


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