The code that follows goes into the Workbook code section. To put it there
(Excel 2003 and earlier):
Open the workbook and right-click on the little Excel icon immediately to
the left of the word "File" in the menu toolbar. Choose [View Code] from the
list that appears.
Copy the code below and paste it into the code module presented to you, make
changes to the Const values declared (as the name of the sheet where you want
to keep this special Metadata). Save and close the workbook. When you open
it up again, the footers will automatically be revised.
I've gathered the 1st 3 metadata items from the workbook values themselves
rather than having you type them in. If you really want to type stuff into
those cells (Status still is a manual entry), then we can modify the code
easily enough. The document name and last date saved will not be valid until
the file is has actually been saved once - if you're creating a brand new
file, that is.
Here's the code:
Option Explicit
'code by J.Latham
'email: (e-mail address removed)
'
'change these definitions as required for
'your workbook setup for the metadata sheet
Private Const infoSheetName = "SpecialSheet"
Private Const docNameCell = "B1"
Private Const docAuthorCell = "B2"
Private Const docSavedDateCell = "B3"
Private Const docStatusCell = "B4"
Private Sub Workbook_Open()
'this automatically updates the contents
'of the 1st 3 items on the information sheet
Dim infoSheet As Worksheet
Set infoSheet = _
ThisWorkbook.Worksheets(infoSheetName)
infoSheet.Range(docNameCell) = ThisWorkbook.Name
infoSheet.Range(docAuthorCell) = ThisWorkbook.Author
infoSheet.Range(docSavedDateCell) = _
FileDateTime(ThisWorkbook.FullName)
Set infoSheet = Nothing ' housekeeping
'the Status entry is a manual entry
'update all footers
UpdateWorksheetFooters
End Sub
Private Sub UpdateWorksheetFooters()
Dim infoSheet As Worksheet
Dim anySheet As Worksheet
Dim footerText As String
Set infoSheet = _
ThisWorkbook.Worksheets(infoSheetName)
footerText = "Document Name: " & _
infoSheet.Range(docNameCell) & vbLf
footerText = footerText & "Author: " & _
infoSheet.Range(docAuthorCell) & vbLf
footerText = footerText & "Last Saved: " & _
infoSheet.Range(docSavedDateCell) & vbLf
footerText = footerText & "Status: " & _
infoSheet.Range(docStatusCell)
For Each anySheet In ThisWorkbook.Worksheets
With anySheet.PageSetup
.LeftFooter = footerText
'you can also use these sections if you like
'.CenterFooter = "here is center of footer"
'.RightFooter = "right aligned in footer"
End With
Next
Set infoSheet = Nothing
End Sub
kmewing said:
I need to create an Excel template that prints some standard metadata in the
footer of each worksheet. The metadata consists of Document Name, Author,
Last Save Date, and Status. (Status is a one-word entry.) To populate the
footer, I would like to have a separate worksheet (named “Metadataâ€) where
the user would fill in the values for these four fields, then these values
would automatically propagate to the footers of the other worksheets in the
workbook. I’d like the footers to appear as follows:
Document Name: <name>
Author: <name>
Last Saved: <date>
Status: <value>
I expect I’ll need to use VB scripting to make this work. Can anyone point
me to a source where I can get some guidance on doing the above task? I’m
not deeply versed in VB myself but I’m willing to try it. Thanks for any
help.