Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Automatically runing a macro

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Automatically runing a macro

"Tom Ogilvy" wrote in news:OtNqSOPaDHA.2632
@TK2MSFTNGP09.phx.gbl:

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Automatically runing a macro

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.

--
sb
"Tom Ogilvy" wrote in message
...
Private sub Workbook_Open()
if thisworkbook.Path = "" then
mymacro
End if
End Sub


since the workbook won't have a path when it is created from the template,
this will only run during that one opening.


--
Regards,
Tom Ogilvy

Peter Longstaff wrote in message
. ..
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Automatically runing a macro

Peter,

The Workbook_Open goes into the ThisWorkbook module...

--
sb
"Peter Longstaff" wrote in message
. ..
"Tom Ogilvy" wrote in news:OtNqSOPaDHA.2632
@TK2MSFTNGP09.phx.gbl:

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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Automatically runing a macro

Dave Peterson wrote in :

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.



Peter Longstaff wrote:

"Tom Ogilvy" wrote in news:OtNqSOPaDHA.2632
@TK2MSFTNGP09.phx.gbl:

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



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

Peter
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
table with a runing clock Les Excel Worksheet Functions 2 April 11th 08 05:28 PM
Runing a macro in a workbook from another macro in other workbook dhatul Excel Discussion (Misc queries) 0 January 13th 06 06:27 AM
Runing two macros triggered by a button Paul B Excel Discussion (Misc queries) 1 December 9th 05 12:51 AM
Runing two macros triggered by a button Dave Peterson Excel Discussion (Misc queries) 0 December 9th 05 12:43 AM
error after runing MS update last weel 10/13/2005 Quan Excel Discussion (Misc queries) 0 October 17th 05 05:42 PM


All times are GMT +1. The time now is 08:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"