I'm very new to the world of VBA, but I need a VBA script to insert the filename as a footer into Excel. Ideally, I would like to insert the first 7 characters of the filename into the footer of each tab in an excel files.I have about 5000 Excel files that need this macro. The loop through codes i have tried so far have been unsuccessful. I've only ever been able to insert headers/footers into each worksheet and all tabs (not multiple files) using the following code:
<code>Sub InsertHeaderFooter() ' inserts the same header/footer in all worksheets Dim ws As Worksheet Application.ScreenUpdating = False For Each ws In ActiveWorkbook.Worksheets Application.StatusBar = "Changing header/footer in " & ws.Name With ws.PageSetup .RightFooter = "f&" End With Next ws Set ws = Nothing Application.StatusBar = False End Sub </code></pre>
<code>Sub InsertHeaderFooter() ' inserts the same header/footer in all worksheets Dim ws As Worksheet Application.ScreenUpdating = False For Each ws In ActiveWorkbook.Worksheets Application.StatusBar = "Changing header/footer in " & ws.Name With ws.PageSetup .RightFooter = "f&" End With Next ws Set ws = Nothing Application.StatusBar = False End Sub </code></pre>