Problem with GetObject function in MS Access

dsoderstrom
dsoderstrom used Ask the Experts™
on
I am trying to open excel  from vba code in Access 2010 using the GetObject function.
My code is as follows:
     
      dim xlObj as Object
      Set xlObj = GetObject(, "excel.application")

I get the following error  on the second line:

      Run-time error '429':
      ActiveX component can't create object

What is strange is that this was working for a few iterations and now it doesn't.
The first time if failed I did a decompile of the data base and that got it to work for one time.  But then if failed with the same message again.

Any ideas on what is causing this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Hi,

Are you sure Excel is open at the time?

if not use CreateObject

Regards

Author

Commented:
Wow, I guess that should have been obvious to me!
Thank you for the help.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Generally, I put an error handler at the beginning of the code module.

Then I use the GetObject syntax to set the reference to an existing instance of Excel.  If that raises an error, it goes to the error handler, where I use syntax similar to:

If Err.Num = x  then   'don't remember the error code off the top of my head
    Set xlObj = CreateObject("Excel.Application")
    Resume Next
Else

...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial