简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM