autorun macro

  • Thread starter Thread starter hke
  • Start date Start date
H

hke

I want to have a macro run each time I open a new excel file based upon
a specific template. I saved the macro in the ThisWorkbook module of
the template, but still the macro has to be manually run for each new
file. Is there a way for new files to autorun the macro in their
ThisWorkbook module?
 
hke said:
I want to have a macro run each time I open a new excel file based upon
a specific template. I saved the macro in the ThisWorkbook module of
the template, but still the macro has to be manually run for each new
file. Is there a way for new files to autorun the macro in their
ThisWorkbook module?

Is the macro called Workbook_Open() ?

GB
 
hke said:
Yes it is

Hmm - I asked because I have the following code in a test template:

Private Sub Workbook_Open()
MsgBox "hi"
End Sub

It's in the workbook code.

It works 100% - every time!

So, what are you doing that's different?

GB
 
Mine is also in the workbook code.

The macro puts the path of the file in the title area. I guess its like
this: The file needs to be saved to set the path and therefore nothing
happens at opening since the file has not been saved.

It would be preferable to have the macro run automatically after save
 
hke said:
Mine is also in the workbook code.

The macro puts the path of the file in the title area. I guess its like
this: The file needs to be saved to set the path and therefore nothing
happens at opening since the file has not been saved.

It would be preferable to have the macro run automatically after save

Can you not save immediately after open?

GB
 
Put the macro in a general module with a different name such as AddPath

In the BeforeSave event in the workbook module put in code like

Application.Ontime Now + TimeValue("00:00:05"),"AddPath"
 
Back
Top