How do I determine if a workbook is a template?

G

Guest

I have code that needs only execute when a template is opened. The code saves
the template as .xls, and in that state the code should not execute. I
thought about deleting the code when the template is saved as a sheet,
 
G

Guest

Oops - please disregard. Accidentally hit "Post" instead of "Close". Dang -
those buttons are close together...
 
G

Guest

Prob'ly oughta post the solution I found:

The code in the template saves it as *.xls. Problem is, XL didn't recognize
it as a regular workbook, still as a template. Had to add this to the SaveAs:

ThisWorkbook.SaveAs _
Filename:=fname _
password:="xxxxxx" _
FileFormat:=xlWorkbookNormal

The last parameter is what makes XL recognize it as a "normal" workbook.

Then, at the top of the code, I added this line:

If ThisWorkbook.FileFormat <> xlTemplate Then Exit Sub

Voila! The code won't be executed if it's not a template!

I'm outtahere!
 

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