Solved

Determine xlfileformat of Excel workbook using VBA

Posted on 2012-03-21
3
1,719 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 80

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 80

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now