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!

GetObject : (, Excel.application) & ("c\MYDOCU~1\book1.xls","

Status
Not open for further replies.

larryjr

Technical User
Aug 27, 2001
20
JP
Hi All,

I need your help on GetObject function;

The context;
Set myObj = GetObject( ,"Excel.Sheet")
fails though the other conxtext;
Set myObject = GetObject("c:MYDOCU~1\book1.xls", _
"Excel.Sheet")
succeeds even both cases are using "Excel.Sheet".
(NOTE: Former case should use "Excel.Application" instead
of "Excel.Sheet")
HELP file on ERROR 429 says it depends on the class
registerd in the registry but I have no clue to
which class is the good one looking into the HKCR
in case of handling object library such as HTML object,
MS Wallet and even Windows Media Player including Excel.

How I can generally determin the appropriate context for
the registered ActiveX classes from the HKCR registry information in using GetObject function ?

Thanks in advance.

LarryJR
 
Search for help at the MS Knowldedge Base under Automating Office. I think the on line help in Access also has a snippet or two. These will teach you how to properly instansiate, create or use, and destroy an OLE object.

Note: Always destroy the object, less 'ya want a bazillion copies of Excel floating around....

set objExcel = Nothing. Tyrone Lumley
augerinn@gte.net
 
Thanks Lumley,

I tried your suggestion searching kb with the key word
"Automating Office" to get 142 items matched, however
no items gave the answer to my question;
*******************************************************
How I can generally determin the appropriate context for
the registered ActiveX classes from the HKCR registry information in using GetObject function ?
*******************************************************

The matched results are all the same, giving the code
for "use as it is".
Behind these codes, there should be "a rule" and I would
like to know it.
In this case, the key is "class registered in system
registry" and how I can pick up the correct class for
GetObject function in various objects ?

 
I wouldn't go chasing the registery. I've been using Access 5 years and haven'y had to manipulate the registery directly (yet).

To automate, here are the general guidelines.

1. Set your reference to the proper object model.
2. Declare the object: dim objExcel as Excel.Application
3. Instansiate the object:
A. GetObject- If there is a current Instance or if the file already exsists.
Set objExcel = GetObject("C:\MySpreadsheet.xls,"Excel.Application")
B. CreateObject- No current instance, and you don't want to open a file when the object is started.
Set objExcel = createobject("Excel.Application")
C. Using New and Set- If you have a reference in the type library, and can use a specific object variable (early binding)
Set objExcel = New Excel.Application

Here's some KB articles:

Q178510 PRB: Excel Automation Method of Object '_Global'Failed
Q167223 Microsoft Office 97 Automation Help File Available
Q222101 HOWTO: Find and Use Office Object Model Documentation Tyrone Lumley
augerinn@gte.net
 

Thanks Lumly.

Sorry for responding to your reply.
Because of NIMDA virus, our ISP server would not work
couple of weeks.

I will spend couple of days to read the KB you suggested.

Thanks again.
 
I'm not really sure what your asking. It is my belief that if you are instantiating an instance of Excel without specifying a worksheet name, then you must use the GetObject(,"Excel.Application"), vice "Excel.Sheet").

Of course, using GetObject assumes that an instance of MS Excel is already running. Try this.

Dim appExcel as Excel.Application

On Error Resume Next
Set appExcel = GetObject(,"Excel.Application")
If Err.Number <> 0 Then
Set appExcel = CreateObject(&quot;Excel.Application&quot;)
Err.Clear
End If

On Error Goto ErrorHandler
...

This will try to open an already running instance of Excel. If one does not exist then the code will create a new instance.
Neil Konitzer, President
Freisoft
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top