How to open 1 session of Excel via Access - currently getting mult

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using the following code to open a session of Excel and file(s). The
user can then return to the form and run another query which calls this
procedure again and is opening another session of Excel. I end up with
several Excel sessions being open. I'd like to be able to check to see if a
session of Excel is already open and use that session to open the additional
file(s). What's the best way to do this?

Dim XL As Excel.Application
Set XL = CreateObject("Excel.Application")

XL.Visible = True ' make Excel visible

If strExcelFileName <> "" Then
XL.Workbooks.Open FileName:=strExcelFileName
End If
 
Replace the CreateObject() with GetObject() on the subsequent calls to this
routine. Help has the proper syntax..
 
Hmm, this looks like it should be simple but I'm still having trouble.

Now, I'm using the following code and I get an err.number 432, "File name or
class name not found during automation." I know the file exists so it
appears its a class problem but I don't know where to look/what to fix...

Dim objXL As Object

If strExcelFileName <> "" Then
Set objXL = GetObject(strExcelFileName, "Excel.Application")

End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top