Solved

Determine xlfileformat of Excel workbook using VBA

Posted on 2012-03-21
3
1,760 Views
Last Modified: 2012-03-21
I am writing an application (in Access 2010) that works with Excel workbooks. These workbooks may be from any version of Excel (i.e. Excel 200. 2003, 2007, etc.). In order to work with these files I need to know the appropriate xlfileformat value to use.
I am looking for a function/procedure that will examine the file and return its xlfileformat.
I've seen suggestions of looking at the extension and using a series of Select/Case statements, but this would seem to be an incomplete solution at best. I would like to be using a function that I don't have to update with a new Case statement every time a new release of Office comes out. Is the xlfileformat value or something that readily translates to it stored as an attribute of the Excel file? In the metadata perhaps?
0
Comment
Question by:shambalad
  • 2
3 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 37750361
Excel has a FileFormat properties for workbooks

Set wb = xlApp.ActiveWorkbook      'Assumes that xlApp has been instantiated as Excel.Application
MsgBox wb.FileFormat

This property will return an integer value. There are many possibilities, the most important being:
xlExcel8 56 Excel8    .xls
xlOpenXMLTemplate 54 Open XML Template .xltx
xlOpenXMLTemplateMacroEnabled 53 Open XML Template Macro Enabled .xltm
xlOpenXMLWorkbook 51 Open XML Workbook  .xlsx
xlOpenXMLWorkbookMacroEnabled 52 Open XML Workbook Macro Enabled .xlsm
0
 
LVL 81

Expert Comment

by:byundt
ID: 37750394
If you don't want to open the file first, you can get its file type (as text) from the FileSystemObject:
Function FileType(filePathAndName As String) As Integer
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(filePathAndName)
s = UCase(f.Name) & " is a " & f.Type
MsgBox s
End Function

Open in new window

0
 
LVL 7

Author Closing Comment

by:shambalad
ID: 37750595
Thank you,
Todd
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question