Automatically runing a macro

  • Thread starter Thread starter Peter Longstaff
  • Start date Start date
P

Peter Longstaff

Hi All,

I am new to VBA so please forgive this rather simple question.

I have written a macro which calls a user form and I can fill in all of the
data and populate the worksheet as I requrie.

My problem is as follows. I have saved the worksheet as a template. I want
the macro to run the first time a new document is created based on the
template. How do I do that ?

TIA
Peter
 
Private sub Workbook_Open()
if thisworkbook.Path = "" then
mymacro
End if
End Sub

Hi Tom,

thanks for this but i do not know where to place this function. DO I place
it in the workbook or the specific sheet ?

TIA
Peter
 
Tom,

Thanks! I like it!!! And I have just the place to use it...
I had been using a check on the workbook name, but this is more appropriate.
Should even work for workbooks that are sent via email.
 
Dave Peterson said:
right click on the excel icon to the left of the File|Edit|View|...
menubar.

Select view code and paste it in that right hand window.

Your macro code should continue to live in a General module.

Thanks everyone, that has sorted it.
I owe you all one.

Peter
 
Back
Top