W
wildetudor
I wanted to have my documents' TOC updated everytime I save them, and
therefore I added the following two macros into Normal.dotm:
Sub FileSave()
ActiveDocument.TablesOfContents(1).Update
ActiveDocument.Save
End Sub
Sub FileSaveAs()
Dialogs(wdDialogFileSaveAs).Show
ActiveDocument.TablesOfContents(1).Update
ActiveDocument.Save
End Sub
However, when I save a document as a result of pressing Yes in a file close
dialog ("Do you want to save the changes to...?"), the TOC does not update. I
have therefore found out the code of the FileClose macro and created a new
macro in Normal.dotm with the same and with the same code plus the
ActiveDocument.TablesOfContents(1).Update line that updates the TOC. I now
therefore have a FileClose macro that looks like this:
Sub FileClose()
ActiveDocument.TablesOfContents(1).Update
If Not ActiveDocument.Saved Then
Select Case MsgBox("Do you want to save the changes to " _
& Chr(34) + ActiveDocument.Name + Chr(34) & "?", _
vbExclamation + vbYesNoCancel, "Microsoft Office Word")
Case vbYes
FileSave
Case vbNo
ActiveDocument.Close wdDoNotSaveChanges
Case vbCancel
'Do Nothing
End Select
Else
ActiveDocument.Close wdDoNotSaveChanges
End If
End Sub
However, documents saved from the file close dialog still not have their
TOCs updated. Have I got anything wrong here? Thanks for any help.
therefore I added the following two macros into Normal.dotm:
Sub FileSave()
ActiveDocument.TablesOfContents(1).Update
ActiveDocument.Save
End Sub
Sub FileSaveAs()
Dialogs(wdDialogFileSaveAs).Show
ActiveDocument.TablesOfContents(1).Update
ActiveDocument.Save
End Sub
However, when I save a document as a result of pressing Yes in a file close
dialog ("Do you want to save the changes to...?"), the TOC does not update. I
have therefore found out the code of the FileClose macro and created a new
macro in Normal.dotm with the same and with the same code plus the
ActiveDocument.TablesOfContents(1).Update line that updates the TOC. I now
therefore have a FileClose macro that looks like this:
Sub FileClose()
ActiveDocument.TablesOfContents(1).Update
If Not ActiveDocument.Saved Then
Select Case MsgBox("Do you want to save the changes to " _
& Chr(34) + ActiveDocument.Name + Chr(34) & "?", _
vbExclamation + vbYesNoCancel, "Microsoft Office Word")
Case vbYes
FileSave
Case vbNo
ActiveDocument.Close wdDoNotSaveChanges
Case vbCancel
'Do Nothing
End Select
Else
ActiveDocument.Close wdDoNotSaveChanges
End If
End Sub
However, documents saved from the file close dialog still not have their
TOCs updated. Have I got anything wrong here? Thanks for any help.