Determine type of workbook

stuartgb100

Active Member
Joined
May 10, 2015
Messages
287
Office Version
  1. 2021
Platform
  1. Windows
Hi,

What is the best way to establish the type of workbook that has opened
(eg template, macro-enabled etc) ?

This is in Excel 2010.

Thanks.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Your question was pretty generic.

Can you explain exactly what you are trying to do?
Are you trying to get this in VBA to do something with it?
Is this part of a bigger process?
 
Last edited:
Upvote 0
You code use something like:
Code:
ActiveWorkbook.FileFormat
to get the File Format of the active workbook.

It will return a numerical code. Here is a document that tells you what they are: https://www.rondebruin.nl/win/s5/win001.htm
 
Upvote 0
Thanks,

I had found Ron's thread - that's what led me to fileformat.

I have a project which I wish to distribute via a template.

When a colleague opens the template (or more accurately, a copy of it), they will be
'forced' to choose a save filename and folder. Their file will then be saved with a
.xlsm file extension.

From then onwards, when user opens that file, I need to know if it's the template or a .xlsm file
so that I can control the code.

The only other way I can think, would be to strip out any specific template workbook code before
allowing the save as a .xlsm file.

Thanks again.
 
Upvote 0
From then onwards, when user opens that file, I need to know if it's the template or a .xlsm file
so that I can control the code.
You should be able to identify it by looking at the extension, like this:
Code:
    Select Case Right(ActiveWorkbook.Name, 4)
        Case "xlsm"
            MsgBox "File is macro enabled"
        Case "xltm", "xltx"
            MsgBox "File is an template"
        Case Else
            MsgBox "Something else"
    End Select
 
Upvote 0
Brilliant.

Many thanks for your time and interest.

Best Regards.
 
Upvote 0
The default action on a template is New, so myTemplate.xltm will open as myTemplate1. It doesn't acquire an extension until it's saved (myTemplate.xlsm/xlsb/csv/whatever).
 
Upvote 0
You are welcome!

It looks like that Ron did something similar to my code at the bottom of that link, instead using the FileFormat code instead of the file extension.
But same idea...
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top