Solved

Method of Object failed making Excel Visible (XL97)

Posted on 2002-03-14
9
1,179 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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6866118
At least but not last: Check versions between development machine/target machine.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now