I am unsure how to close an application..pls help to chk my codes..

fulltime

Registered User.
Local time
Tomorrow, 05:58
Joined
Mar 24, 2006
Messages
56
Hi all, below is a sample of my code


Sub Export()
Dim objExcel As Excel.Application
Set objExcel = CreateObject("Excel.Application")

DoCmd.OutputTo acOutputQuery, langName & " Q", acFormatXLS, tbFile, False 'export the query

OpenFile (tbFile) 'using shellexecute to open tbFIle, file tat was exported to excel

Call Convert 'a function tat consists of excel macro to be run on tbFile

CloseFile (tbFile) 'using shellexecute to close tbFile

objExcel.Quit '
Set objExcel = Nothing


wat i am trying to do is to output my query from MS access to excel, then in excel, run the function convert() which consists of excel macros. After convert(), the excel application will close. However, the next time i execute export(), it will show me the runtime 1004 error. saying tat some codes in the convert() failed. I need to acknowlege the error, then when i retry the export() again, it works.

I realised that there is something wrong with the way i close the excel application, this might be bcos, of 2 statments to open the excel application, - CreateObject("Excel.Application") and also the openFile () which uses shell execute to open the excel application.

can anyone chk my codes above for me pls? I am in urgent need of guidance on this issue.. thks..


Thks
FT :)
 
Hi fulltime,

Not sure if this will work but what happens if you place on the end of your code

Code:
Excel.Application.Close

Robert88
 

Users who are viewing this thread

Back
Top Bottom