Thread: [Solved] Error with exit macro
View Single Post
 
Old 01-26-2017, 06:40 AM
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 Error with exit macro

Hey guys,
I have this exit macro which has worked flawlessly in both Mac and Windows until yesterday when I used it in a Windows table (Mac works flawlessly in tables). The code stalls on the fourth line "Selection.Fields.Unlink." If I reverse the sequence of the third (ActiveDocument.Unprotect) and fourth lines, it works for the tables but stalls in the body of the text. I'm stumped. Suggestions?

Code:
Sub UnlinkFieldsCensus()
' Unlink Fields Macro
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveUp Unit:=wdParagraph, Count:=1, Extend:=wdExtend
    ActiveDocument.Unprotect
    Selection.Fields.Unlink
    Selection.MoveRight Unit:=wdCharacter, Count:=2
          Dim Bookmark As Bookmark
      ActiveDocument.Bookmarks.ShowHidden = True
      If ActiveDocument.Bookmarks.Count >= 1 Then
         For Each Bookmark In ActiveDocument.Bookmarks
            Bookmark.Delete
         Next Bookmark
      End If
End Sub
Reply With Quote