PDA

View Full Version : [SOLVED:] xlsm or xltm file extension



stuartgb100
06-30-2015, 07:35 AM
I'm trying to tell whether user has just opened a template file or a macro-enabled workbook.

If I use activeworkbook.fullname:

for the .xlsm I would get: test file.xlsm

but the template just gives: test file template1

So the template does not give the file extension (.xltm) and the template file has been renamed template1.

I assume this is because template1 is a newly-created file and therefore has not been saved.

So what would be the best way to test which file has been opened ?

Perhaps something like:

If the active book has the file extension ".xlsm" then exit
but
If the active book contains the string "template1" in the workbook name
Then do something else

Many thanks.

SamT
06-30-2015, 08:01 AM
So what would be the best way to test which file has been opened ?
I think you are confusing ActiveWorkbook with Opened workbook and New Workbook.

The ActiveWorkbook is merely the one you are looking at on the screen. It doesn't matter if it is a CSV file, a TXT file, an XLSM, XLST, XLSX, XLSB, or a brand new file that has never been saved.

If you Open a Workbook, it will have an Extension in its' name. Therefor you can usually tell the difference between any saved workbook and a new unsaved workbook programmatically with


If Instr("Name of Book", ".") <> 0 Then 'Book has been saved.

Paul_Hossler
06-30-2015, 08:04 AM
ThisWorkbook.FileFormat might be safer


Probably requires a little investigation. For example, if I open a XLMT to edit, .FileFormat= xlOpenXMLTemplateMacroEnabled (= 53) and a XLSX .FileFormat= xlOpenXMLWorkbookMacroEnabled (52)

Look at

https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.xlfileformat.aspx

.FileFormat= 0 = Just created from template = Not saved

stuartgb100
06-30-2015, 10:43 AM
Sam & Paul, many thanks.

Sam - yes my mistake (doh), it will be the activeworkbook that needs checking.

Paul - I had not known of FileFormat - I will investigate.

Thanks to you both.

ps: how to mark a post as 'solved' please ?

Paul_Hossler
06-30-2015, 10:54 AM
ps: how to mark a post as 'solved' please ?

Above Post #1, Thread Tools, you get a "Mark Solved" radio button