View Full Version : Excel Template mode
Annodomini2
09-21-2011, 01:15 AM
Hi all,
I am trying to create some VBA code that is only activated from the template when a new instance is created.
I am using Excel 2003.
I've tried searching, but get so many hits I'd be here all day!
Maybe this is something straight forward that I'm not aware of, but is it possible to detect in VBA when you are in Template mode??
Thanks
Andy
Bob Phillips
09-21-2011, 01:36 AM
What do you mean by in template mode?
Annodomini2
09-21-2011, 01:38 AM
The File is open as a template, rather than the file is open as a document.
Bob Phillips
09-21-2011, 01:42 AM
When you open a template, it just creates a standard Excel workbook (based upon that template). If you actually mean the template is opened, that is not new based on that template, just check its file type.
Annodomini2
09-21-2011, 03:18 AM
There may be a better way, but this is what I worked out:
Dim FileName As String
Dim Extension As String
FileName = ActiveWorkbook.Name
Extension = LCase(Right(FileName, 3))
If Extension = "xls" Then
Annodomini2
09-21-2011, 03:44 AM
Had to change it to:
If Not Extension = "xlt" Then
Quirkily enough Excel doesn't add the extension until the file is saved! lol
Bob Phillips
09-21-2011, 07:16 AM
Had to change it to:
If Not Extension = "xlt" Then
Better to use
Extension = LCase(Right(FileName, Len(FileName) - InStrRev(FileName, ".")))
If Not Extension Like "xlt*" Then
Quirkily enough Excel doesn't add the extension until the file is saved! lol
Until it is saved, there is no type.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.