Solved

Method of Object failed making Excel Visible (XL97)

Posted on 2002-03-14
9
1,234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding to a VBA? 6 90
Question about INSTR  - need to extract data MS ACCESS query 6 68
VB6 - Convert HH:MM into Decimal 8 75
checkbox to hide entire section 10 75
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

732 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