Solved

Determine xlfileformat of Excel workbook using VBA

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

752 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