buddythunder
Programmer
Hi all,
I'm testing our macros in preparation for upgrading from Office 97 to Office 2002/XP. I'm having some problems with Word quitting when the last document is closed. In the code below, when run with no documents initially open in Word 2002, the first activedocument.close runs fine and the macro continues, but the one in the for loop cause Word to close. Why should this be, and how can I stop it? I could add a document at the start and kill it at the end, but it's an ugly kludge, any thoughts on this one?
Thanks for your time
Dave
I'm testing our macros in preparation for upgrading from Office 97 to Office 2002/XP. I'm having some problems with Word quitting when the last document is closed. In the code below, when run with no documents initially open in Word 2002, the first activedocument.close runs fine and the macro continues, but the one in the for loop cause Word to close. Why should this be, and how can I stop it? I could add a document at the start and kill it at the end, but it's an ugly kludge, any thoughts on this one?
Thanks for your time
Dave
Code:
Option Explicit
Sub Main()
Dim aDoc As Document
Dim i As Integer
Dim StrPath As String
If Dialogs(wdDialogFileOpen).Show = 0 Then
MsgBox "Routine cancelled - Table Of Contents to close", vbOKOnly + vbCritical
End
End If
StrPath = ActiveDocument.Path
ActiveDocument.Close
With Application.FileSearch
.NewSearch
.LookIn = StrPath
.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
.FileName = "*.*"
.Execute
End With
For i = 1 To Application.FileSearch.FoundFiles.Count
Set aDoc = Documents.Open(Application.FileSearch.FoundFiles.Item(i))
If aDoc.Revisions.Count > 0 Then
MsgBox "You cannot run macros on files that have unnaccepted" & vbCrLf _
& "changes. Please ensure you accept or reject all tracked " & vbCrLf _
& "changes on all files.", vbOKOnly + vbCritical, "Tracked Changes Located"
aDoc.Close
Set aDoc = Nothing
End
End If
aDoc.Close savechanges:=wdDoNotSaveChanges
Set aDoc = Nothing
Next i#
...