Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default Add standard header and footer to new worksheet

I am a VBA novice writing an Excel 2002 template. I wish to add a standard
header and footer to any new worksheet that is added. My attempt to achieve
this has fallen at the first hurdle! Can anyone help me with this?

My code is:-

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim ws As Worksheet
Dim fs As String
fs = "Ariel Size 8" ' Font Size
fc = "FF0000" ' Colour = Red
Application.ScreenUpdating = False
Set ws = ActiveWorkbook.Worksheets
With ws.PageSetup
.LeftHeader = ""
.CenterHeader = "My Company Name" & fs & "K(fc)"
.RightHeader = ""
.LeftFooter = "&F" & Chr(10) & "&A" & fs & "K(fc)" 'Document Name and
Workbook Name
.CenterFooter = ""
.RightFooter = "&D" & Chr(10) & "&T" & fs & "K(fc)" 'Current date and
Current Time
End With
Set ws = Nothing
End Sub



Thanks in anticipation.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Add standard header and footer to new worksheet

In the procedure you have, the Sh variable in the parameter list is a
reference to the newly created worksheet. You should use that
reference rather than the Ws reference. Change

With ws.PageSetup

to

With Sh.PageSetup

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]



On Tue, 11 May 2010 07:29:01 -0700, Grey Old Man
wrote:

I am a VBA novice writing an Excel 2002 template. I wish to add a standard
header and footer to any new worksheet that is added. My attempt to achieve
this has fallen at the first hurdle! Can anyone help me with this?

My code is:-

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim ws As Worksheet
Dim fs As String
fs = "Ariel Size 8" ' Font Size
fc = "FF0000" ' Colour = Red
Application.ScreenUpdating = False
Set ws = ActiveWorkbook.Worksheets
With ws.PageSetup
.LeftHeader = ""
.CenterHeader = "My Company Name" & fs & "K(fc)"
.RightHeader = ""
.LeftFooter = "&F" & Chr(10) & "&A" & fs & "K(fc)" 'Document Name and
Workbook Name
.CenterFooter = ""
.RightFooter = "&D" & Chr(10) & "&T" & fs & "K(fc)" 'Current date and
Current Time
End With
Set ws = Nothing
End Sub



Thanks in anticipation.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default Add standard header and footer to new worksheet

Thanks. The following code works OK, but how do I add the font attributes?

Private Sub Workbook_NewSheet(ByVal sh As Object)
Dim fs As String
Dim fn As String
Dim fc As String
fs = "8" ' Font Size
fn = "Arial" ' Font Name
fc = "FF0000" ' Font Colour = Red
Application.ScreenUpdating = False
With sh.PageSetup
.LeftHeader = ""
.CenterHeader = "My Company Name"
.RightHeader = ""
.LeftFooter = "&F" & Chr(10) & "&A"
.CenterFooter = ""
.RightFooter = "&D" & Chr(10) & "&T"
End With
End Sub


Thanks in anticipation.

"Chip Pearson" wrote:

In the procedure you have, the Sh variable in the parameter list is a
reference to the newly created worksheet. You should use that
reference rather than the Ws reference. Change

With ws.PageSetup

to

With Sh.PageSetup

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]



On Tue, 11 May 2010 07:29:01 -0700, Grey Old Man
wrote:

I am a VBA novice writing an Excel 2002 template. I wish to add a standard
header and footer to any new worksheet that is added. My attempt to achieve
this has fallen at the first hurdle! Can anyone help me with this?

My code is:-

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim ws As Worksheet
Dim fs As String
fs = "Ariel Size 8" ' Font Size
fc = "FF0000" ' Colour = Red
Application.ScreenUpdating = False
Set ws = ActiveWorkbook.Worksheets
With ws.PageSetup
.LeftHeader = ""
.CenterHeader = "My Company Name" & fs & "K(fc)"
.RightHeader = ""
.LeftFooter = "&F" & Chr(10) & "&A" & fs & "K(fc)" 'Document Name and
Workbook Name
.CenterFooter = ""
.RightFooter = "&D" & Chr(10) & "&T" & fs & "K(fc)" 'Current date and
Current Time
End With
Set ws = Nothing
End Sub



Thanks in anticipation.

.

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
Show where worksheet is saved in the header/footer Justyna Excel Discussion (Misc queries) 6 September 4th 07 05:00 PM
Duplicate A5 worksheet with header & footer onto an A4 original Peter Newman Excel Discussion (Misc queries) 0 December 7th 06 01:47 PM
how to include a variable in the header and/or footer of a worksheet tmacke Excel Discussion (Misc queries) 2 April 14th 06 10:13 PM
Is it possible to copy a header/footer from one worksheet to anoth DLC Excel Discussion (Misc queries) 1 September 28th 05 02:01 PM
Landscape worksheet with portrait header/footer SNOWED-IN Excel Discussion (Misc queries) 3 April 11th 05 05:18 AM


All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"