Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Help with a template file | New Users to Excel | |||
Macro Template File | Excel Worksheet Functions | |||
Error:Invalid File format,while opening an Excel Template file | Excel Programming | |||
Macro to run when file is created from a template | Excel Programming | |||
Excel template file, where is it? | Excel Programming |