?
Solved

Method of Object failed making Excel Visible (XL97)

Posted on 2002-03-14
9
Medium Priority
?
1,264 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 400 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

862 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