Discussion:
Why can't create "Excel.Application" Object using "CreateObject" function
(too old to reply)
j***@sompojapan.com.hk
21 years ago
Permalink
Hi, there
I try to create an "Excel.Application" object using CreateObject function, I got "nothing" from the return variable without any error messages, but It works well on another computer, we have the same environment settings(include same references setting) on those 2 computers: Win2k/Sp4, VB6/Sp5, Mdac_type2.7, the following is source code snippet

Public appWorld As Excel.Applicatio
Public wbWorld As Excel.Workboo
Sub Setup()
On Error Resume Next 'ignore error
Set appWorld = GetObject(, "Excel.Application"
If Err.Number <> 0 The
Set appWorld = CreateObject("Excel.Application") 'run i
End I
Err.Clea
End Su

I got "nothing" from "appWorld", even I remark all of error handle lines, the same result I got, pls help me,thanks!
Jezebel
21 years ago
Permalink
If you're using GetObject or CreateObject you don't need the project
reference, and this might be the problem. CreateObject returns an object
from whatever library is registered (in the registry) as
"Excel.Application". This might be different from the library you have added
to the project's references. Eg, if the project reference is to Excel 9, but
the user has installed Excel 10.

Try removing the reference and change the declarations from 'As Excel....'
to 'as object'.
Hi, there,
I try to create an "Excel.Application" object using CreateObject
function, I got "nothing" from the return variable without any error
messages, but It works well on another computer, we have the same
Public appWorld As Excel.Application
Public wbWorld As Excel.Workbook
Sub Setup()
On Error Resume Next 'ignore errors
Set appWorld = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set appWorld = CreateObject("Excel.Application") 'run it
End If
Err.Clear
End Sub
I got "nothing" from "appWorld", even I remark all of error handle lines,
the same result I got, pls help me,thanks!
B1j
21 years ago
Permalink
NEVER, EVER, EVER, use GetObject. It is an EVIL function, always use CreateObject instead
What if you use GetObject on an instance of Excel that has already been created with CreateObject from another program, and is in the middle of running some code. Unpredictable results could happen. Use CreateObject instead, to be sure of a fresh instance that you know isn't going to be tied up or busy.
Jezebel
21 years ago
Permalink
What a silly thing to say. Sometimes a reference to an existing instance of
an application is precisely what you *do* want. And if you do, that's the
function you use: that's what it's for. Of course it has to be handled with
care. That's true of ANY interprocess work in Windows. If you can't stand
the heat, get out of the kitchen.
Post by B1j
NEVER, EVER, EVER, use GetObject. It is an EVIL function, always use
CreateObject instead.
Post by B1j
What if you use GetObject on an instance of Excel that has already been
created with CreateObject from another program, and is in the middle of
running some code. Unpredictable results could happen. Use CreateObject
instead, to be sure of a fresh instance that you know isn't going to be tied
up or busy.
Bob Butler
21 years ago
Permalink
Post by B1j
NEVER, EVER, EVER, use GetObject. It is an EVIL function, always use
CreateObject instead.
inane
Post by B1j
What if you use GetObject on an instance of
Excel that has already been created with CreateObject from another
program, and is in the middle of running some code.
what if you do? what if that's what you want? what if you know how to code
to deal with the situation?
Post by B1j
Unpredictable
results could happen.
only if you don't know what you are doing
Post by B1j
Use CreateObject instead, to be sure of a fresh
instance that you know isn't going to be tied up or busy.
For Office apps that is often the simplest approach. It is the way I
usually do it for just that reason but there are times when GetObject may be
more appropriate.
--
Reply to the group so all can participate
VB.Net... just say "No"
Continue reading on narkive:
Loading...