Run a macro if file is a template

S

SLW612

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!
 
T

Tom Ogilvy

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.
 
B

Bernie Deitrick

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

Bernie
 
T

Tom Ogilvy

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 said:
Hey, Tom! Nice to see you in the groups again. Hope all is well.

Bernie
 
B

Bernie Deitrick

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 said:
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.
 
T

Tom Ogilvy

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.
 

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