Switch between Access and Excel

  • Thread starter Thread starter Brent
  • Start date Start date
B

Brent

Hi All

I'm controlling an Excel instance in my Access database
and I'd like to know how I can switch the window focus
between Access and Excel. I am running code to do things
in both the current database and the workbook. (i.e.
using recordset objects to populate a worksheet and
grabbing data from the worksheet to populate a table in
Access).

However, when I control Excel through Acess via VBA, I
cannot get the Excel.exe process to end properly. I tried
making explicit references to my Excel object (i.e
myExcel.activesheet.range....) My code can end the Excel
process successfully without doing any routines or
functions pertaining to the current database.

I'm hoping that by switching the window focus from Access
to Excel and vice versa, will solve my problem.

I hope I haven't confused anyone.
Thanks for all your help.

Brent
 
Switching focus likely won't fix your problem of EXCEL not quitting. It can
be extremely subtle, but such circumstances are almost always caused by
omitting a full reference to some EXCEL object and VBA therefore creating
one for you.

Oftentimes, it's errors such as this:

xlApp.Workbooks("WorkbookName").Worksheets("SheetName").Range(Cells(1,1),
Cells(2,2))

Note that Cells is not fully referenced, and this creates the extra
reference that then can prevent EXCEL from closing. This would be the
correct syntax:

xlApp.Workbooks("WorkbookName").Worksheets("SheetName").Range(xlApp.Workbook
s("WorkbookName").Worksheets("SheetName").Cells(1,1),
xlApp.Workbooks("WorkbookName").Worksheets("SheetName").Cells(2,2))
 
Back
Top