Tuesday, August 10, 2004 - Posts

Removing index entries from Word documents

I know, this has absolutely nothing to do with Smart Development or even with .Net development... It's just that I needed to totally remove all index entries from a Word document today, and unfortunately this great Office tool doesn't include such a feature (or have I missed it?). Therefore, I quickly wrote a hack in VBA for Word, and thought I'd share it with you:

Sub StripIndexEntries()
    Dim c As Long
    Dim fieldCode As String
   
    c = 1
    While (c <= ActiveDocument.Fields.Count)
        fieldCode = ActiveDocument.Fields(c).code
       
        If InStr(fieldCode, "XE ") > 0 Then
            ActiveDocument.Fields(c).Delete
        Else
            c = c + 1
        End If
    Wend
End Sub

That's it. Happy un-indexing!

with 0 Comments