Link to home
Start Free TrialLog in
Avatar of jelen
jelen

asked on

Method of Object failed making Excel Visible (XL97)

Sorry for the stupid question - I am new to VB.

I have a simple VB program that launches Excel and creates a new workbook.  It works on a lot of machines, but on one machine (400 miles away in our New Jersey office....), it returns an error.

Code snippet:
Sub Main()
    Dim oExcelApp As Excel.Application
    On Error GoTo err_handler
1:    Set oExcelApp = CreateObject("Excel.Application")
2:    oExcelApp.Visible = True
3:    oExcelApp.UserControl = True

err_handler:
  MsgBox "Error " & Err.Number & " - " & Err.Description & " at line # " & Erl, vbCritical

Our New Jersey rep sees Excel open, then he gets:
Error 2147417851 - Method '~' of Object '~' Failed at line #2".

Any help would be greatly appreciated.

Bill
ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
also, what is usercontrol?
At least but not last: Check versions between development machine/target machine.
Avatar of jelen
jelen

ASKER

Richie,

Thanks for the posts.  .UserControl = True will tell VB that I want Excel to remain open after the last programmatic reference to it.

In you last comment:  Check versions:  This is definitely an issue - the development machine has Excel 2002 and the target machines have Excel 97 through 2002.  This KB article suggests to use late binding instead of early binding: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q242375

 I will try that in the AM.  Thanks for your help.

Bill
i have never heard regarding usercontrol property.
But what i can say is (in a general "vision"):
Every object is "alive" until last reference to it is active.
So, if your
Dim oExcelApp As object
is inside a sub/function, that object reference could be "die" the second after End sub/funcion is reached.

If you want to maintain that object in memory until program finish, do it a public variable and, specifically set:

oExcelApp.quit
set oExcelApp=nothing
when you don't need it.
That will ensures that excel is closed and all references to it are cleared.
Cheers
Hi, any progress?
Hi jelen,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Richie_Simonetti's comment(s) as an answer.

jelen, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Moving to the paq

kb
Experts Exchange Moderator