Run Macro Automatically When Excel 2003 Opens

C

CBender

!!! HELP PLEASE !!!!!


I have a password protected MS Excel 2003 spreadsheet with several Pivot
Tables and numerous tabs collecting and displaying data based on these Pivot
Tables.

Specific individuals can open this MS Excel 2003 file for updates using a
password and others simply open the file in "Read Only" mode.

I have seven (7) Pivot Tables I need to have refreshed each time the MS
Excel 2003 file opens. I created a macro called "RefreshAllPivotTables" in
This Workbook. The macro goes to each of the Pivot Tables and refreshes the
linked data when you use "ctrl+u".

I need to ensure that each of the Pivot Tables always display the latest
information available. However, our directors and managers find it too
"inconvenient" to run the macro to refresh the data themselves.

Thus I have been trying to get this macro to run automatically when the MS
Excel 2003 file opens.

I selected the third tab called "R3 Total" (there are a total of fifteen
(15) tabs in this MS Excel 2003 file) and selected "View Coding". Using the
VB Editor, I entered the following code:


Option Explicit
Sub Auto_Open()
Call RefreshAllPivotTables
End Sub


It doesn't seem to matter if I open the MS Excel 2003 file in "Read Only"
mode or use the password to open the file, my stored macro fails to execute
automatically. Does it matter which tab is used or opened first? I need my
"RefreshAllPivotTables" macro to run regardless of which of the fifteen (15)
tabs are opened first.

A co-worker mentioned that MS Excel 2003 no longer supports auto-run macro
functions when a file opens. Is this true or am I simply doing something
wrong?

Any HELP would be appreciated.

Thanks,
 
J

Jim Thomlinson

Auto open still works if placed in a standard code module. It is the old way
of doing it but it still works. I have used it as a standard code plugin but
generally I now use the Open even int Thisworkbook.

Right click the XL icon beside File on the main menu and select View Code.
this takes you to thisworkbook. Just above the code window are 2 drop down
boxes. Change the one on the left to workbook. The one on the right will list
all of the events. Select the open event. A code stub is created. Any cod in
that stub will execute when the file is opened.
 
D

Dave Peterson

I usually use Auto_Open -- just because it's easier to explain how to implement
it.

So as long as you have the code in a General module and the users are allowing
macros to run, it should execute.

Now a question...

How is this workbook being opened? Is it a manual File|Open (ctrl-o) or
doubleclicking on the filename in explorer?

Or is it opened by procedure in another workbook? And if that's the case, if
you're using a shortcut key to run that procedure, then remove the shift key in
that shortcut key combination.

And I've never personally seen a problem with the code you posted, but others
have.

One solution is to wait a second and then call your procedure:

Option Explicit
Sub Auto_Open()
Application.OnTime earliesttime:=Now + timeserial(0,0,1), _
procedure:=RefreshAllPivotTables
End Sub

The theory is that it gives excel a chance to regroup and catch up to what it's
supposed to be doing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top