how to close the application?

Posted on 2004-11-22
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
    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

    change this

    Private m_oExcel As Excel.Application


    Private m_oExcel As object
    LVL 16

    Expert Comment

    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...


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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.

    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    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…
    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…

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now