Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Excel 2010 file from Access 2010 VBA

I have both Excel 2003 and Excel 2010 on my machine. I'm using VBA in Access 2010 to open 2010 .xlsx files in Excel, but I notice they seem to be "opening" in Excell 2003 because that little "Converting data" dialog box pops up for a moment.

Is there an easy way to be sure that Excel 2010 "opens" before the files open?

Thanks,

Ed

like image 230
edsac64 Avatar asked Apr 22 '13 21:04

edsac64


1 Answers

I don't have two versions of Excel on my computer so cannot test but I would think that the following would open the default Excel version, which I assume you would have as 2010, and then open the file. The debug.print will tell you which Excel version is opened.

Alternatively, do you need 2003? Why not uninstall?

Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")

xlApp.visible = TRUE

xlApp.Workbooks.Open "C:\FolderName\FileName.xlsx", True, False
Debug.Print xlApp.Version
set xlApp = NOTHING

EDIT: Sorry, I should also note that this opens a new instance of Excel on your machine, at the end of what you want to do you should use

xlApp.Quit

To close the instance so you don't have multiple instances running on your machine.

Also, if you need to see the spreadsheet for any reason

xlApp.Visible = True

Will do it for you

like image 142
Simon1979 Avatar answered Oct 06 '22 00:10

Simon1979