Access OLE Query export to Excel
Keywords: Access OLE Query export to Excel
Question:
I am trying to figure out how to export my Query results to an Excel spreadsheet using Access OLE. I used the tech db and got to the point where I can see the standard Query results using the code below. I need suggestions for the export to Excel?? I am using Office XP. All of this worked with sendkeys in Office 2000 but stopped working when I transferred to Office XP.AccessDB = ObjectOpen("Access.Application") ADB = AccessDB.Application ; make sure use full db path/name ADB.OpenCurrentDatabase ("c:\Aerostd\ieee98.mdb") ADB.Visible = @true ADB.UserControl = @true ADBCmd = ADB.docmd ADBCmd.OpenQuery("PapersAndAuthors") ADB.closecurrentDatabase ADB.Quit ;' Release the object variable ObjectClose(AccessDBAnswer:
This works:; Create xl spread sheet from downloaded access database xlFilename = "C:\Aerostd\PapersAndAuthors.xls" acQuery = "PapersAndAuthors" if Fileexist(xlFilename) then filedelete(xlfilename) ; Delete old sheet AccessDB = ObjectOpen("Access.Application") ; OLE XP Version ADB = AccessDB.Application ; Open Access ADB.OpenCurrentDatabase ("c:\Aerostd\ieee98.mdb") ; Open DB ; ADB.Visible = @true ; Make access visible ADBCmd = ADB.docmd ;Create OLE command first part ADBCmd.TransferSpreadsheet(1, 8, acQuery, xlFilename, @True) ; Export Query to Spreadsheet objectClose(ADB) ; Close oLE objects objectClose(ADBCmd) ObjectClose(AccessDB)