View Full Version : [SOLVED:] Kill/Close that open file
Trying to get rid of an open Word file from XL. Can this be done? Dave
edit: I should add that XL didn't open it to begin with.
Killian
03-27-2005, 03:23 PM
Hi Dave,
Here's a routine that will do that. I'm testing for a specific file here so I guess you will need to change the name.
Sub CloseWordFile()
Dim objWordApp, d
On Error GoTo errortrap
'attempt to get an existing running copy of Word
Set objWordApp = GetObject(, "Word.Application")
'close the specified document
For Each d In objWordApp.Documents
If d.Name = "Test.doc" Then d.Close
Next
Exit Sub
errortrap:
'an error will occur if Word is not open
'just exit here or display a message
End Sub
or you can get rid of the If.. Then and use d.Close to close them all and objWordApp.Quit close Word
Many thanks Killian. I was missing the Getobject line of code. I still can't seem to get rid of the word application. I'm using the following code which does close the document but Word keeps running and I can't figure out how to get rid of it. Any suggestions? Dave
ps. Sorry re. format. I can't seem to access XL on this computer?
Set Objwordapp = GetObject(filepath)
With Objwordapp
.Close
End With
Set Objwordapp = Nothing
Zack Barresse
03-28-2005, 09:40 AM
Dave, couldn't you use ...
Objwordapp.Quit
.. to close the Application?
Thanks Zack but that just wouldn't work for me. I solved this with the following code. I'll try the tags. Dave
Set Objwordapp= Getobject(,"Word.application")
With Objwordapp
.Application.Quit
End With
Set Objwordapp = Nothing
edit: spelling
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.