Solved

Determine xlfileformat of Excel workbook using VBA

Posted on 2012-03-21
3
1,808 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 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