ActiveX Components

R

Roger Converse

Hello,

Within Access, I am trying to check if an instance of Excel is open. If one
isn't, then I would like to open one. Although the Autotext feature allows
me to key the following:

Dim objXl As Excel.Application

When I put my cursor over it, the message reads "Object variable or with
block variable not set."

When I run the code, I receive an error stating:

I am receiving an error stating "ActiveX component can't create object."
Error 429.

Sample code is below. I am erroring at GetObject(, "Excel.Application").
When Excel is open, the code runs fine. When Excel is closed, I get the
error message.

Any assistance is appreciated.

blnCreated = False

Set objXl = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
blnCreated = True
Set objXl = CreateObject("Excel.Application") 'for late binding
End If
With objXl.Application
.Visible = True
.Windows("Personal.xls").Activate
.Run "module1.macOpenPO"
End With

If blnCreated = True Then objXl.Quit

I have the references for Excel 11.0 checked in Tools | References, so am
not sure if I am missing something else there.

Thank you,
Roger
 
T

Tom van Stiphout

On Mon, 17 Dec 2007 07:02:02 -0800, Roger Converse

You missed a line before this code block:
on error resume next

The whole point of the GetObject line is that you will generate a
runtime error when Excel is not yet running. As long as you keep going
(and my extra line makes that possible), the next If Err statement
will detect if it is not, and then call CreateObject to launch Excel.

-Tom.
 

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

Top