-
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'
-
How about MyXL.Quit right before the Set MyXL = Nothing?
-
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.
-
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
-
Forum Rules