View Single Post
  #4   Report Post  
Dave O
 
Posts: n/a
Default Replace &F in header with text

The code that follows will ask you to select the files you want to
change. This is a one-file-at-a-time deal, unfortunately; the code to
automate the entire process is a touch trickier than I have time for at
this moment.

The code applies the new header to each tab in the document, using the
filename instead of the tab name. You'll still need to work out the
parsing- changing the file from MyFile123456.xls to MyFile.

Sub Filename_in_header()
Dim SName As Variant
Dim Response As String

Do

'select a file
Application.Dialogs(xlDialogOpen).Show

'Apply new header to each sheet in the file
For Each SName In Sheets
Sheets(SName.Name).Select
With ActiveSheet.PageSetup
.RightHeader = "Doc No. " & Mid(ActiveWorkbook.Name, 1, 5)
End With
Next SName
'save the workbook with changes; close
ActiveWorkbook.Save
ActiveWindow.Close

'Ask whether user wants to update another file
Response = MsgBox("Update another file?", vbYesNo)
Loop Until Response = vbNo

End Sub