Link to home
Start Free TrialLog in
Avatar of shambalad
shambaladFlag for United States of America

asked on

Determine xlfileformat of Excel workbook using VBA

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?
ASKER CERTIFIED SOLUTION
Avatar of byundt
byundt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of shambalad

ASKER

Thank you,
Todd