dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: open & close EXCEL with VB6

  1. #16
    Join Date
    Apr 2006
    Posts
    28
    Jim,
    Thanks again for the advice. I will try the "Break Point" thing and let you know what happens.
    As to trying an ADO program, YES, I want to try it. I wrote a large database program 5 years ago for a friend and his company is still using it to this day. The differance was that all data is input manually and I constructed the databases from scratch. "Wizards" and "Import Data" will be all new to me. Even if I could get my current project working I still want to learn something new. I guess I just want to understand what is going on with the one I started before I tackel somethin new. I need to learn what is causing the problem if I'm going to avoid similar problems in the future.
    Thanks again and I'll update any progress I make, Garner

    Paul,
    When I first started having this problem I put this code:


    Code:
    Dim MyXL As Object   ' Variable to hold reference to Microsoft Excel.
        Dim ExcelWasNotRunning As Boolean   ' Flag for final release.
    
    ' Test to see if there is a copy of Microsoft Excel already running.
        On Error Resume Next   ' Defer error trapping.
    ' Getobject function called without the first argument returns a
    ' reference to an instance of the application. If the application isn't
    ' running, an error occurs.
        Set MyXL = GetObject(, "Excel.Application")
        If Err.Number <> 0 Then ExcelWasNotRunning = True
        Err.Clear   ' Clear Err object in case error occurred.
    
    ' Check for Microsoft Excel. If Microsoft Excel is running,
    ' enter it into the Running Object table.
        DetectExcel
    
        Set MyXL = GetObject(App.Path & "\K and D (152598).xls")
    
    ' Show Microsoft Excel through its Application property. Then
    ' show the actual window containing the file using the Windows
    ' collection of the MyXL object reference.
        MyXL.Application.Visible = True
        MyXL.Parent.Windows(1).Visible = True
        
    
    Workbooks.Open FileName:="D:\K and D (152598).xls"
    in my "Form Activate" event thinking that it might solve the problem and also save a lot of code in each label event. The program would error as soon as the label was clicked. I think the error was "Global Variable Failed." I tried several variations, same code in the "Form Load" event, split the code between "General Declarations" & "Form Activate", and half a dozen other things. Always said that the Global Failed.
    As to several instanses of Excel running, I watched what you said. Excel blinks in the task bar and right back out just like the Excel window on the screen. I will try looking on the "Task Manager" as you suggested and get back with the results.
    Thanks for the advice! I'll keep trying, Garner

  2. #17
    Join Date
    Dec 2003
    Posts
    2,750
    Once again, definining a variable in a Sub, Function, Event, etc will localize it to that routine. Once that routine terminates the variable is out of scope and destroyed. If you don't properly terminate the application to which that variable points to before it is destroyed there is a good chance that the application will remain in memory. This could cause problems upon re-use or creation of a new instance of the application.

    I would either terminate Excel (Quit method) before the routine finishes executing, or declare a global or module level variable for your Excel object and then terminate it when your application terminates.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  3. #18
    Join Date
    Apr 2006
    Posts
    28
    To "Super Paul",
    I think you figured out how to fix my program!!!!! I studied your suggestion,

    I would either terminate Excel (Quit method) before the routine finishes executing, or declare a global or module level variable for your Excel object and then terminate it when your application terminates.
    I really didn't know how to do this but I tried adding,

    Code:
    On error resume next
    MyXL.Application.Quit
    Set MyXL = Nothing
    to my form activate event. I ran several short tests and it worked perfect!!! I need to do some more tests but I was so excited that I just had to let you know. Thanks for all of the help, Paul & EVERYONE who spent time and effort tryin to figure this out!
    Garner

  4. #19
    Join Date
    Apr 2006
    Posts
    28
    Sorry everyone,
    I spoke to soon. I went back to testing the program and it's right back to the same thing as before. I guess I'll start reading on how to declare a global or module level variable for your Excel object and then terminate it when your application terminates.
    Back to work, Garner

Similar Threads

  1. problem in opening XML with EXCEL via VB6
    By eranfox in forum VB Classic
    Replies: 5
    Last Post: 08-09-2007, 07:18 AM
  2. Replies: 0
    Last Post: 10-10-2002, 05:36 AM
  3. Replies: 2
    Last Post: 10-09-2002, 09:58 AM
  4. open connection to excel from a webpage
    By fareeda in forum ASP.NET
    Replies: 1
    Last Post: 06-26-2002, 02:59 PM
  5. Open and close application
    By Zoe Thompson in forum VB Classic
    Replies: 0
    Last Post: 11-23-2001, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center