Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Need help with a Macro or VB code for Header/Footer

Looking for a macro to enter a custom header and a footer

Header would have:

title of worksheet
job#
client name
date


footer would have:

file path
author
page# of total pages

I saw how to create file paths and dates but I'm trying to combo everything
into an easy to enter series of text boxes so our personnel don't have to
open "page setup" each time...
any suggestions would be appreciated
Thanks

--
jgbadingerjr
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Need help with a Macro or VB code for Header/Footer

From VBA help files:

Worksheets("Sheet1").PageSetup.CenterHeader = "&D page &P of &N"

You can also do:

Sub heddft()
Worksheets(1).PageSetup.CenterHeader = "&b &14 My Worksheet" _
& vbCrLf & "Job 1" & vbCrLf & "Some Client" & vbCrLf & "&d"
End Sub

For footer just substitute CenterFooter fow CenterHeader, or LeftHeader,
LeftFooter, etc. It is all the same syntax. The &b and &14 and &d inside
the quote marks set bold = true, Font size = 14 and Current date respectively.
"jgbadingerjr" wrote:

Looking for a macro to enter a custom header and a footer

Header would have:

title of worksheet
job#
client name
date


footer would have:

file path
author
page# of total pages

I saw how to create file paths and dates but I'm trying to combo everything
into an easy to enter series of text boxes so our personnel don't have to
open "page setup" each time...
any suggestions would be appreciated
Thanks

--
jgbadingerjr

  #3   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Need help with a Macro or VB code for Header/Footer

Hi -
Here are a couple of options. Put either one in the ThisWorkbook module.

Because a long pathname can encroach on the center footer, the second
version 'stacks' the strings in the left footer.

Version1:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
'worksheet title in A1
.LeftHeader = Range("A1")
'job# in A2 and client in A3
.CenterHeader = Range("A2").Value & " --- " & Range("A3")
.RightHeader = Format(Date, "dd-mmm-yyyy")

.LeftFooter = ThisWorkbook.FullName & Chr(13) ' or ThisWorkbook.Name
.CenterFooter = ThisWorkbook.Author
.RightFooter = "Page &P of &N"
End With
End Sub

Version2:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
'worksheet title in A1
.LeftHeader = Range("A1")
'job# in A2 and client in A3
.CenterHeader = Range("A2").Value & " --- " & Range("A3")
.RightHeader = Format(Date, "dd-mmm-yyyy")

.LeftFooter = ThisWorkbook.FullName & Chr(13) & _
ThisWorkbook.Author & Chr(13) & _
"Page &P of &N"
.CenterFooter = ""
.RightFooter = ""
End With
End Sub

--
Jay


"jgbadingerjr" wrote:

Looking for a macro to enter a custom header and a footer

Header would have:

title of worksheet
job#
client name
date


footer would have:

file path
author
page# of total pages

I saw how to create file paths and dates but I'm trying to combo everything
into an easy to enter series of text boxes so our personnel don't have to
open "page setup" each time...
any suggestions would be appreciated
Thanks

--
jgbadingerjr

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Need help with a Macro or VB code for Header/Footer

Hi,
thanks for the help but im not sure where this goes...where is the
ThisWorkbook Module?

Thanks
--
jgbadingerjr


"Jay" wrote:

Hi -
Here are a couple of options. Put either one in the ThisWorkbook module.

Because a long pathname can encroach on the center footer, the second
version 'stacks' the strings in the left footer.

Version1:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
'worksheet title in A1
.LeftHeader = Range("A1")
'job# in A2 and client in A3
.CenterHeader = Range("A2").Value & " --- " & Range("A3")
.RightHeader = Format(Date, "dd-mmm-yyyy")

.LeftFooter = ThisWorkbook.FullName & Chr(13) ' or ThisWorkbook.Name
.CenterFooter = ThisWorkbook.Author
.RightFooter = "Page &P of &N"
End With
End Sub

Version2:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
'worksheet title in A1
.LeftHeader = Range("A1")
'job# in A2 and client in A3
.CenterHeader = Range("A2").Value & " --- " & Range("A3")
.RightHeader = Format(Date, "dd-mmm-yyyy")

.LeftFooter = ThisWorkbook.FullName & Chr(13) & _
ThisWorkbook.Author & Chr(13) & _
"Page &P of &N"
.CenterFooter = ""
.RightFooter = ""
End With
End Sub

--
Jay


"jgbadingerjr" wrote:

Looking for a macro to enter a custom header and a footer

Header would have:

title of worksheet
job#
client name
date


footer would have:

file path
author
page# of total pages

I saw how to create file paths and dates but I'm trying to combo everything
into an easy to enter series of text boxes so our personnel don't have to
open "page setup" each time...
any suggestions would be appreciated
Thanks

--
jgbadingerjr

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Need help with a Macro or VB code for Header/Footer

Right-click on the Excel Icon left of File on the menu bar or on the title bar
left of the filename if the sheet window is not maximized.

Select "View Code".

Paste the code into that module.


Gord Dibben MS Excel MVP

On Sat, 17 Mar 2007 16:29:09 -0700, jgbadingerjr
wrote:

Hi,
thanks for the help but im not sure where this goes...where is the
ThisWorkbook Module?

Thanks




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Need help with a Macro or VB code for Header/Footer

Thank you...all of you big help! 8)
--
jgbadingerjr


"Gord Dibben" wrote:

Right-click on the Excel Icon left of File on the menu bar or on the title bar
left of the filename if the sheet window is not maximized.

Select "View Code".

Paste the code into that module.


Gord Dibben MS Excel MVP

On Sat, 17 Mar 2007 16:29:09 -0700, jgbadingerjr
wrote:

Hi,
thanks for the help but im not sure where this goes...where is the
ThisWorkbook Module?

Thanks



  #7   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default VB coding assistance for Header/Footer

I'm using the following per the instructions below, and located at: http://www.cpearson.com/excel/headfoot.htm

However the 2 rows highlighted in Red are not pulling the Data from cells B2 and B3.

Secondly I would like to make a Font Transition to 22PTS for for cells B2 and B3.


Private Sub Workbook_BeforePrint(Cancel As Boolean)

ActiveSheet.PageSetup.Leftheader = "&B&18&""Arial"" Stock: "
Format (Worksheets("CALL_Profitability").Range("B2").Valu e)

ActiveSheet.PageSetup.Centerheader = "&B&18&""Arial"" Option: "
Format (Worksheets("CALL_Profitability").Range("B3").Valu e)

End Sub

Thanks,
Hank
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
what code pulls in contents of a cell in an Excel header/footer? Ronnyk Excel Discussion (Misc queries) 3 September 13th 07 08:18 PM
Add Font to Header/Footer macro JHL Excel Discussion (Misc queries) 4 January 5th 07 07:45 PM
Need some code for header/ footer, another case of "last saved Ron de Bruin Excel Programming 0 December 28th 06 09:20 PM
VB. NET Code to Change Excel Worksheet Header/Footer. Elena Excel Programming 2 March 13th 06 06:17 PM
Header and Footer Macro dhuang via OfficeKB.com Excel Discussion (Misc queries) 1 October 31st 05 04:14 PM


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