Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close Excel from Access using VBA? 1

Status
Not open for further replies.

datras

Programmer
Jun 6, 2001
28
DK
Hi All
I have tried to use automation between Access and Excel for creating charts. It works all right until I close the Excel application. I close Excel with .quit as described in Help and Excel disappears from applications in the task manager, however, it continues to run under processes, which creates problems the next time I open Excel. I use Access 2000 and the code is below.

I would be very pleased if any one could help me with solving this problem.
Lena



Dim objXLApp As New EXCEL.Application
Dim objXLBook As EXCEL.Workbook
Dim objResultsSheet As EXCEL.Worksheet
Dim objChartSheet As EXCEL.Worksheet

objXLApp.Workbooks.Add
Set objXLBook = objXLApp.ActiveWorkbook
objXLBook.Sheets(1).Select
objXLBook.Sheets(1).Name = "Data"
objXLBook.Sheets(2).Select
objXLBook.Sheets(2).Name = "Charts"
Set objResultsSheet = objXLBook.Worksheets("Data")
Set objChartSheet = objXLBook.Worksheets("Charts")

' Code transferring data from Access to Excel and creates a number of charts in Excel

objXLBook.Close 'SaveChanges:=False
objXLApp.Quit

Set objResultsSheet = Nothing
Set objChartSheet = Nothing
Set objXLBook = Nothing
Set objXLApp = Nothing
 
Try looking at the following two links:

API: Find out if an application is currently running (to find out if Excel or Word is running in the background)

API: Close another application (requires ClassName. Will pick up the code from above, and pass the classname as an argument to this function)

It worked for me, although I am still having trouble with Access as I want this all to be done with command buttons. One to open Excel SS, then enter data into it, then another button to id the active worksheet, assign a new name to it based on Access filename, save and close it.

Good luck!

Busmgr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top