ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I determine if a workbook is a template? (https://www.excelbanter.com/excel-programming/392719-how-do-i-determine-if-workbook-template.html)

Clayman

How do I determine if a workbook is a template?
 
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,
--
Adios,
Clay Harryman

Clayman

How do I determine if a workbook is a template?
 
Oops - please disregard. Accidentally hit "Post" instead of "Close". Dang -
those buttons are close together...
--
Adios,
Clay Harryman


"Clayman" wrote:

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,
--
Adios,
Clay Harryman


Clayman

How do I determine if a workbook is a template?
 
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!
--
Adios,
Clay Harryman


"Clayman" wrote:

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,
--
Adios,
Clay Harryman



All times are GMT +1. The time now is 11:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com