Create auto open VBA for ALL excel files opened?

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
 
You have so many threads going on, I can't keep track. Several people crosspost when they first start using these amazing forums. Here is an article on crossposting. http://www.excelguru.ca/node/7

To solve the problem with the code that I posted, use an On Error routine. Your routine took 20-40 seconds which is quite long.

e.g.
Code:
Private Sub aOpen_WorkbookOpen(ByVal Wb As Workbook)
    On Error Resume Next
    If ActiveWorkbook.Name <> ThisWorkbook.Name Then MyMacro
End Sub

Here are some of the cross posts:
'Original thread?, http://www.mrexcel.com/forum/showthread.php?t=575178
'http://www.mrexcel.com/forum/showthread.php?t=576295
'http://www.ozgrid.com/forum/showthread.php?t=157749
'http://www.excelforum.com/excel-programming/790772-need-help-cleaning-up-vba-add-in-code.html
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You have so many threads going on, I can't keep track. Several people crosspost when they first start using these amazing forums. Here is an article on crossposting. http://www.excelguru.ca/node/7

To solve the problem with the code that I posted, use an On Error routine. Your routine took 20-40 seconds which is quite long.

e.g.
Code:
Private Sub aOpen_WorkbookOpen(ByVal Wb As Workbook)
    On Error Resume Next
    If ActiveWorkbook.Name <> ThisWorkbook.Name Then MyMacro
End Sub

Here are some of the cross posts:
'Original thread?, http://www.mrexcel.com/forum/showthread.php?t=575178
'http://www.mrexcel.com/forum/showthread.php?t=576295
'http://www.ozgrid.com/forum/showthread.php?t=157749
'http://www.excelforum.com/excel-programming/790772-need-help-cleaning-up-vba-add-in-code.html
Gotcha, and yes, sorry for the multiple posts...I didn't want to keep "bumping" the old one, so i wasn't sure if I should start a new thread on this forum or troll the other excel forums out there. Not to mention I didn't take into consideration this past weekend was a holiday, hence nobody responding. lol

I will insert the code you wrote and report back to see if I can get the add-in to run properly. Thank you again for your time and attention, it is much apprecaited!
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,853
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top