I am trying to write a macro to replace all instances of an Index entry with an expanded entry. What I've written so far is:
Code: Select all
Sub IndexEntryFieldModify()
'A basic Word macro coded by Charles Kenyon - based on Greg Maxey format
'
' DECLARE VARIABLES / CONSTANTS
Dim oRng As range
Dim oFld As Field
Dim iCount As Long
Dim i As Long
'================================================
' declare old and new entries - change to suit
Const strOld = """Einstein"""
Const strNew = """Einstein, Albert"""
'================================================
' ACTIONS
With ActiveDocument
Let iCount = .Fields.Count
For i = 1 To iCount
If .Fields(i).Type = wdFieldIndexEntry Then
If .Fields(i).Code = " XE " & strOld Then .Fields(i).Code = " XE " & strNew
End If
Next i
End With
On Error GoTo lbl_Exit
' EXIT PROCEDURE
lbl_Exit:
' CLEAR ERROR HANDLER AND OBJECTS
On Error GoTo -1
Set oRng = Nothing
Set oFld = Nothing
Exit Sub
End Sub
Problem 2: I am trying to insert text inside the field code that has quotation marks as part of the text. I do not know if I am doing this correctly because I can't even get it to start running. What I am using is a triple quotation mark (""") where I want this. It occurs to me that trying to read "Einstein" I may need """ & "Einstein" & """ or something completely different.
[*]