R
Rick
In order to generate an Excel report from a query, I've got code to use a
current instance of Excel if it's running already. If Excel isn't running,
then it creates a new instance of Excel. This happens frequently. Here's my
code:
On Error GoTo ErrorHandler
Set db = CurrentDb
Set rst = db.OpenRecordset("qryExcelTemplate")
Set objApp = GetObject(, "Excel.Application")
Set objWorkbook = objApp.Workbooks.Open("C:\Noodle!\Report template.xls")
Set objWorksheet = objWorkbook.Worksheets("Report")
....
ErrorHandler:
If Err.Number = 429 Then
'Excel is not running, open Excel with CreateObject
Set objApp = CreateObject("Excel.Application")
Resume Next
Else
MsgBox "Error No: " & Err.Number & "; Description: " * Err.Description
Resume ErrorHandlerExit
End If
current instance of Excel if it's running already. If Excel isn't running,
then it creates a new instance of Excel. This happens frequently. Here's my
code:
On Error GoTo ErrorHandler
Set db = CurrentDb
Set rst = db.OpenRecordset("qryExcelTemplate")
Set objApp = GetObject(, "Excel.Application")
Set objWorkbook = objApp.Workbooks.Open("C:\Noodle!\Report template.xls")
Set objWorksheet = objWorkbook.Worksheets("Report")
....
ErrorHandler:
If Err.Number = 429 Then
'Excel is not running, open Excel with CreateObject
Set objApp = CreateObject("Excel.Application")
Resume Next
Else
MsgBox "Error No: " & Err.Number & "; Description: " * Err.Description
Resume ErrorHandlerExit
End If