w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Delete Word Fields VBA does not work in Word 2013, worked in Word 2010

Have to tried deleting them by index instead?

For i = 1 to wdDoc.ActiveWindow.Document.Fields.Count
    wdDoc.ActiveWindow.Document.Fields.Item(i).Delete
Next i

I have found sometimes that in loops removing the active object in this case fld is not always successful and VBA Error Messages are less than specific. Also it seems SEQ(Sequence Fields) and XE(IndexEntry Fields) cannot be Unlinked which suggests to me that Delete may fail as well although Microsoft does not specify this is the case.

Edit

Based on comment looping last to first

For i = wdDoc.ActiveWindow.Document.Fields.Count To 1 Step -1
    wdDoc.ActiveWindow.Document.Fields.Item(i).Delete
Next i




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.