Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


how to close the application?

Posted on 2004-11-22
Medium Priority
Last Modified: 2010-05-02


i have open an exel file in my vb application. every time i open this exel file, it remains opens. so any one please tell me how to close this exel file when ever i close the vb form??
Question by:binita11
LVL 52

Expert Comment

by:Carl Tawn
ID: 12642610
Posting a sample of the code you are using would help.  Generally you should be using something like:

    Private m_oExcel As Excel.Application

    Private Sub Form_Load()

        Set m_oExcel = New Excel.Application

        '// Code here to open your workbook, etc

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

        Dim i As Integer
        '// Close all open workbooks
        For i = 1 To m_oExcel.Workbooks.Count
        Next i

        '// Exit Excel
        Set m_oExcel = Nothing

    End Sub

Hope this helps.
LVL 26

Accepted Solution

EDDYKT earned 150 total points
ID: 12643890
change this

Private m_oExcel As Excel.Application


Private m_oExcel As object
LVL 16

Expert Comment

ID: 12655896
All of the above should work, as long as you don't finish your program with the 'End' command.  If you do, you won't be able to use it...


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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…
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…
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…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

581 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