Solved

Method of Object failed making Excel Visible (XL97)

Posted on 2002-03-14
9
1,216 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:jelen
9 Comments
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 6866070
Try:
Sub Main()
   Dim oExcelApp As object
   On Error GoTo err_handler
1:    Set oExcelApp = CreateObject("Excel.Application")
   if not oExcelApp  is nothing then
2:    oExcelApp.Visible = True
3:    oExcelApp.UserControl = True
   end if
exit sub
err_handler:
 MsgBox "Error " & Err.Number & " - " & Err.Description & " at line # " & Erl, vbCritical
end sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6866090
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6866112
also, what is usercontrol?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6866118
At least but not last: Check versions between development machine/target machine.
0
 
LVL 1

Author Comment

by:jelen
ID: 6866439
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
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6868184
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
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6886952
Hi, any progress?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7618312
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
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 7665760
Moving to the paq

kb
Experts Exchange Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question