Consulting

Results 1 to 4 of 4

Thread: Solved: Closing Excel from Word

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Solved: Closing Excel from Word

    In my ongoing TextSelect utility, (posted here for a modified use http://www.vbaexpress.com/forum/show...newpost&t=1466)
    the excel process is left running when the userform is closed. The Excel application is not visible while the Word Userform is open, unless it was visible perviously. The code I'm attempting to use is as follows:
    [VBA]
    Private Sub UserForm_Terminate()
    Dim Datafile As String, DataRoute As String, MyXL As Object
    DataRoute = MyPath.Text & MyFile.Text
    Datafile = MyFile.Text
    If Tasks.Exists("Microsoft Excel - " & Datafile) = True Then
    Set MyXL = GetObject(DataRoute)
    End If
    On Error Resume Next
    MyXL.Windows(Datafile).Close False
    Set MyXL = Nothing
    End Sub

    [/VBA]
    I've also tried variations on this, but without success.
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  2. #2
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    How about MyXL.Quit right before the Set MyXL = Nothing?

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Yeah, basically is you start an instance of Excel, set some variable to indicate that you want to Quit the Excel App at the end. Then just use an If statement to check if you should Quit Excel or not.

    Then like Steiner says just use MyXL.Quit to quit that instance of Excel.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks both,
    I'd tried the quit before, but I think my IF statement was preventing the MyXl value from being set. When I get rid of it, the Quit function works correctly.
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •