Jarvoisier
New Member
- Joined
- Aug 29, 2011
- Messages
- 14
Thanks in advance for any help on this thread. My question is as follows: Is it possible to create a VBA auto-open macro that will run on ALL excel files, not just one specific file? In my line of work it is necessary to format excel spreadsheets in the same manner. With the hope of streamlining the process of processing files, I would like to use the macro code listed below to automatically run every time any excel file is opened rather than having to manually open the file and then push keystrokes to run the macro.
I have researched on this and other forums and have only been able to automatically run a macro when a specific file opens....yet I have not figured out (or learned for that matter) if it is even feasible to create a macro for what I am requesting.
Many thanks in advance and please see the code below for the macro that I'd like to run automatically. Like I mentioned earlier, I can only get this macro to run on the personal.xlsm file itself, and not on successive excel files opened that I would like to have the macro run on automatically.
Private Sub Workbook_Open()
'
' Jarvis_Header_Footer Macro
' Macro recorded 8/23/2011 by Rob Jarvis
'
'
Dim ws As Worksheet
For Each ws In Worksheets
ws.Visible = True
Next
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
With ws.PageSetup
.LeftHeader = ""
.CenterHeader = "&F"
.RightHeader = ""
.CenterFooter = "&A"
.RightFooter = "Page &P of &N"
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.25)
.FooterMargin = Application.InchesToPoints(0.25)
.PrintHeadings = True
.PrintTitleColumns = ""
End With
Next ws
End Sub
I have researched on this and other forums and have only been able to automatically run a macro when a specific file opens....yet I have not figured out (or learned for that matter) if it is even feasible to create a macro for what I am requesting.
Many thanks in advance and please see the code below for the macro that I'd like to run automatically. Like I mentioned earlier, I can only get this macro to run on the personal.xlsm file itself, and not on successive excel files opened that I would like to have the macro run on automatically.
Private Sub Workbook_Open()
'
' Jarvis_Header_Footer Macro
' Macro recorded 8/23/2011 by Rob Jarvis
'
'
Dim ws As Worksheet
For Each ws In Worksheets
ws.Visible = True
Next
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
With ws.PageSetup
.LeftHeader = ""
.CenterHeader = "&F"
.RightHeader = ""
.CenterFooter = "&A"
.RightFooter = "Page &P of &N"
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.25)
.FooterMargin = Application.InchesToPoints(0.25)
.PrintHeadings = True
.PrintTitleColumns = ""
End With
Next ws
End Sub