View Single Post
 
Old 03-06-2015, 08:06 PM
brent chadwick brent chadwick is offline Windows 8 Office 2013
Advanced Beginner
 
Join Date: Mar 2015
Posts: 86
brent chadwick is on a distinguished road
Default Update fields and Tables of Content with one macro

Hi guys, new to this forum and new to vba. I have a user form with a TOC and a field section that needs to be updated often. I wrote some VBA in Mac and it works fine, however when I transfer over to Windows the code does not work-I'm stumped here's the code-

Sub UpdateFields()
'
' UpdateFields Macro
'
'
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
If ActiveDocument.ProtectionType <> wdNoProtection Then
Selection.Range.Sections.First.Range.Select
Selection.Fields.Update
End If
With ActiveDocument
.Unprotect
ActiveDocument.TablesOfContents(1).Update
End With
With ActiveDocument
.Protect wdAllowOnlyFormFields, NoReset:=True
End With

End SubĪ

This runs great in Mac but does not work in Windows and gives me an error code of "The requested member of the collection does not exist". Thanks for your help-
Reply With Quote