Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Run a macro if file is a template

Hi,
I have created an order form template for my colleagues that automatically
opens a userform for order details when it the template is opened. However,
I want to disable the macro if the file has previously been opened and saved
by a colleague - basically, if the file is a template (.xlt), the macro
should run, but if it is a regular workbook (.xls) it shouldn't. I don't
want it to pop up every time we open a saved order form. I have tried the
following code but it's not working and I don't know why:

Sub Auto_Open()

If ThisWorkbook.Name = "*.xlt" Then
MsgBox "Template - macro will run"
Else
MsgBox "Not template - macro will not run"
End If

End Sub



I always get the "Not template" message - I have even added a line to put
ThisWorkbook.Name in a cell and the cell will record the ".xlt" extension so
I'm really confused.

Thanks in advance!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Run a macro if file is a template


If ThisWorkbook.Name Like "*.xlt" Then

HTH,
Bernie
MS Excel MVP


"SLW612" wrote in message
...
Hi,
I have created an order form template for my colleagues that automatically
opens a userform for order details when it the template is opened. However,
I want to disable the macro if the file has previously been opened and saved
by a colleague - basically, if the file is a template (.xlt), the macro
should run, but if it is a regular workbook (.xls) it shouldn't. I don't
want it to pop up every time we open a saved order form. I have tried the
following code but it's not working and I don't know why:

Sub Auto_Open()

If ThisWorkbook.Name = "*.xlt" Then
MsgBox "Template - macro will run"
Else
MsgBox "Not template - macro will not run"
End If

End Sub



I always get the "Not template" message - I have even added a line to put
ThisWorkbook.Name in a cell and the cell will record the ".xlt" extension so
I'm really confused.

Thanks in advance!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Run a macro if file is a template

Fantastic! Many thanks

"Bernie Deitrick" wrote:


If ThisWorkbook.Name Like "*.xlt" Then

HTH,
Bernie
MS Excel MVP


"SLW612" wrote in message
...
Hi,
I have created an order form template for my colleagues that automatically
opens a userform for order details when it the template is opened. However,
I want to disable the macro if the file has previously been opened and saved
by a colleague - basically, if the file is a template (.xlt), the macro
should run, but if it is a regular workbook (.xls) it shouldn't. I don't
want it to pop up every time we open a saved order form. I have tried the
following code but it's not working and I don't know why:

Sub Auto_Open()

If ThisWorkbook.Name = "*.xlt" Then
MsgBox "Template - macro will run"
Else
MsgBox "Not template - macro will not run"
End If

End Sub



I always get the "Not template" message - I have even added a line to put
ThisWorkbook.Name in a cell and the cell will record the ".xlt" extension so
I'm really confused.

Thanks in advance!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Run a macro if file is a template

Just to add a thought.
I think most people test whether the workbook has a path. When a workbook
is created from a template, it won't have a path. when it has been saved, it
will.

--
Regards,
Tom Ogilvy



"SLW612" wrote:

Fantastic! Many thanks

"Bernie Deitrick" wrote:


If ThisWorkbook.Name Like "*.xlt" Then

HTH,
Bernie
MS Excel MVP


"SLW612" wrote in message
...
Hi,
I have created an order form template for my colleagues that automatically
opens a userform for order details when it the template is opened. However,
I want to disable the macro if the file has previously been opened and saved
by a colleague - basically, if the file is a template (.xlt), the macro
should run, but if it is a regular workbook (.xls) it shouldn't. I don't
want it to pop up every time we open a saved order form. I have tried the
following code but it's not working and I don't know why:

Sub Auto_Open()

If ThisWorkbook.Name = "*.xlt" Then
MsgBox "Template - macro will run"
Else
MsgBox "Not template - macro will not run"
End If

End Sub



I always get the "Not template" message - I have even added a line to put
ThisWorkbook.Name in a cell and the cell will record the ".xlt" extension so
I'm really confused.

Thanks in advance!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Run a macro if file is a template

Hey, Tom! Nice to see you in the groups again. Hope all is well.

Bernie


Just to add a thought.
I think most people test whether the workbook has a path. When a workbook
is created from a template, it won't have a path. when it has been saved, it
will.

--
Regards,
Tom Ogilvy





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Run a macro if file is a template

Bernie,

thanks for the comment.

All is and has been well. Just cut down a bit due to other demands and have
done most of my "assisting" in Allexperts.

--
Regards,
Tom Ogilvy


"Bernie Deitrick" wrote:

Hey, Tom! Nice to see you in the groups again. Hope all is well.

Bernie


Just to add a thought.
I think most people test whether the workbook has a path. When a workbook
is created from a template, it won't have a path. when it has been saved, it
will.

--
Regards,
Tom Ogilvy




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Run a macro if file is a template

Tom,

Is there an advantage to working within the AllExperts framework? It seems like the questions are
asked specifically of you, rather than the entire community...

Bernie


"Tom Ogilvy" wrote in message
...
Bernie,

thanks for the comment.

All is and has been well. Just cut down a bit due to other demands and have
done most of my "assisting" in Allexperts.

--
Regards,
Tom Ogilvy


"Bernie Deitrick" wrote:

Hey, Tom! Nice to see you in the groups again. Hope all is well.

Bernie


Just to add a thought.
I think most people test whether the workbook has a path. When a workbook
is created from a template, it won't have a path. when it has been saved, it
will.

--
Regards,
Tom Ogilvy






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Run a macro if file is a template

Bernie,
That is the disadvantage. That and people will ask multiple people the same
question resulting in wasted effort since the people answering really can't
see that until days later if at all and not directly.

the creator approached me to be a contributor many many years ago when he
was starting it up, so I just stuck with it.

--
Regards,
Tom Ogilvy




"Bernie Deitrick" wrote:

Tom,

Is there an advantage to working within the AllExperts framework? It seems like the questions are
asked specifically of you, rather than the entire community...

Bernie


"Tom Ogilvy" wrote in message
...
Bernie,

thanks for the comment.

All is and has been well. Just cut down a bit due to other demands and have
done most of my "assisting" in Allexperts.

--
Regards,
Tom Ogilvy


"Bernie Deitrick" wrote:

Hey, Tom! Nice to see you in the groups again. Hope all is well.

Bernie


Just to add a thought.
I think most people test whether the workbook has a path. When a workbook
is created from a template, it won't have a path. when it has been saved, it
will.

--
Regards,
Tom Ogilvy






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
Help with a template file WiredMike New Users to Excel 4 June 10th 08 01:38 AM
Macro Template File LizW Excel Worksheet Functions 0 September 16th 05 06:26 PM
Error:Invalid File format,while opening an Excel Template file Saurabh Excel Programming 1 January 17th 05 07:15 AM
Macro to run when file is created from a template Jim Birch Excel Programming 2 February 19th 04 03:33 AM
Excel template file, where is it? Kevin McCartney[_2_] Excel Programming 1 February 5th 04 08:10 AM


All times are GMT +1. The time now is 08:35 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"