User Tools

Site Tools


koddump:enhanceindexentries

This is an old revision of the document!


Sub EnhanceIndexEntries()
  Dim doc As Document
  Dim fld As Field
  Dim temp As String
  Dim temp2 As String
  Dim omsg As String
  Dim matches
  Dim re2, re3 As RegExp
  Set re2 = New RegExp
  Set re3 = New RegExp
  re2.Global = False
  re3.Global = False
  re2.Pattern = "\s([0-9]{2})\W"
  re3.Pattern = "\s([0-9]{3})\W"
 
  Dim cnt As Integer
  cnt = 0
 
  Set doc = ActiveDocument
  For Each fld In doc.Fields
    fld.Select
    If fld.Type = wdFieldIndexEntry Then
        cnt = cnt + 1
        temp = fld.Code
        temp2 = re2.Replace(temp, " $1;00$1" & Chr$(34))
        temp3 = re3.Replace(temp2, " $1;0$1" & Chr$(34))
        With Selection.Find
            .Text = temp
            .Replacement.Text = temp3
            .Forward = True
            .Wrap = wdFindStop
            .Format = False
            .Execute Replace:=wdReplaceAll
        End With
    End If
  Next
  Set fld = Nothing
  Set doc = Nothing
  omsg = "Justering av indexeringsinformation klar."
  MsgBox (omgs & cnt)
End Sub
koddump/enhanceindexentries.1205250070.txt.gz · Last modified: 2008/03/11 16:41 by 192.176.230.1