I'm asking this in both Excel and Access forums: I have a button on an Access switchboard form that when clicked runs a query that outputs the results into an Excel workbook called Courses.xls, replacing the previous file of the same name (saving the result).
What it's doing is creating a whole new instance of Excel running, despite the fact that Excel was already open. This creates problems for me since Excel macros that need to be run that belong to a workbook from the first occurrence Excel aren't able to switch to the Courses.xls workbook since it "belongs" to a diffrent occurence of Excel.
What code can I add to this so it will either close Excel after creating this Courses.xls workbook, or have it be able to create the workbook without having to open up a new occurrence of Excel? Any ideas welcome...thanks!
Here's the Access code for the Switchboard form button:
Private Sub cmdCourses_Click()
On Error GoTo Err_cmdCourses_Click
'THIS CREATES THE COURSES.XLS FILE AND REPLACES THE OLD FILE
'BUT OPENS A NEW OCCURRENCE OF EXCEL
DoCmd.OutputTo acQuery, "qryCourses", "MicrosoftExcel(*.xls)", _
"q:\qryResults\Courses.xls", True, ""
Exit_cmdCourses_Click:
Exit Sub
Err_cmdCourses_Click:
MsgBox Err.Description
Resume Exit_cmdCourses_Click
End Sub
What it's doing is creating a whole new instance of Excel running, despite the fact that Excel was already open. This creates problems for me since Excel macros that need to be run that belong to a workbook from the first occurrence Excel aren't able to switch to the Courses.xls workbook since it "belongs" to a diffrent occurence of Excel.
What code can I add to this so it will either close Excel after creating this Courses.xls workbook, or have it be able to create the workbook without having to open up a new occurrence of Excel? Any ideas welcome...thanks!
Here's the Access code for the Switchboard form button:
Private Sub cmdCourses_Click()
On Error GoTo Err_cmdCourses_Click
'THIS CREATES THE COURSES.XLS FILE AND REPLACES THE OLD FILE
'BUT OPENS A NEW OCCURRENCE OF EXCEL
DoCmd.OutputTo acQuery, "qryCourses", "MicrosoftExcel(*.xls)", _
"q:\qryResults\Courses.xls", True, ""
Exit_cmdCourses_Click:
Exit Sub
Err_cmdCourses_Click:
MsgBox Err.Description
Resume Exit_cmdCourses_Click
End Sub