Reply to Message

RE: Removing field codes from Word documents for specific formatting
This is great! But I needed an additional feature for it: Only remove index entries with specific heading levels.

This is my solution:
Note Because I use a Dutch Word 2003 version, the formate names are Dutch too. You should change Kop into heading; Voorwoord into Preface etc.


Attribute VB_Name "IndexMarkeringenVerwijderen"

' IndexMarkeringenVerwijderen Macro
' Macro extended 25-1-2010 by Casey.Dronten
'


'There are a number of field code types. To get a full list of constants for the wdFieldType class, use the Object Brower. In the VBE, press [F2] or choose Object Browser from the View menu. In the Classes list, find wdFieldType to update the Members list. Or simply highlight wdFieldIndexEntry in the subprocedure and press [Shift][F2] to display the constants in the Object Browser.
'Tip

Sub IndexMarkeringenVerwijderen()
Dim doc As Document
Dim fld As Field
Set doc = ActiveDocument
For Each fld In doc.Fields
fld.Select



If (Selection.ParagraphFormat.Style Like "Kop [0-9]") Or (Selection.ParagraphFormat.Style Like "Voorwoord") Or (Selection.ParagraphFormat.Style Like "Index") Then
'MsgBox Selection.ParagraphFormat.Style
If fld.Type = wdFieldIndexEntry Then
Response = MsgBox("Wilt u deze indexmarkering verwijderen? [" & Selection.Text & "] opmaakprofiel: " & Selection.ParagraphFormat.Style, vbYesNoCancel, "Indexmarkering verwijderen")
If Response = vbYes Then
fld.Delete
End If
If Response = vbCancel Then
Exit For
End If
End If
End If

Next
Set fld = Nothing
Set doc = Nothing
End Sub




Casey
Posted by Casey-Dronten
Updated - 25th Jan 2010