PDA

View Full Version : VBA code to force invoke Excel 2007 instead of 2003 (from Access)



noinkynoinky
05-11-2010, 08:42 AM
Hi All,

I've created some vba code in Access to export its data table to Excel. Everything works just fine except:

- one user has both Excel 2003 and 2007 installed.
- for him, the code exports the data to Excel 2003.
- I need it to export to 2007, because there is some additional formatting/sorting code that is written for 2007 and is not compatible syntax for 2003.

This is how I'm setting up my Excel objects:

Dim ApXL As Object
Dim xlWBk As Object
Dim xlWSh As Object

Set ApXL = CreateObject("Excel.Application")

Set xlWBk = ApXL.Workbooks.Add
ApXL.Visible = True

Set xlWSh = xlWBk.Worksheets("Sheet1")


Ideally, there'd be some way to do something like

Set ApXL = CreateObject("Excel2007.Application")

to force 2007 to be used.

If anybody has any ideas on this, I'd greatly appreciate it!

Bob Phillips
05-11-2010, 08:46 AM
Try using GetObject, and get your user to have Excel 2007 running and not 2003 when they run your app.