G
Greg Maxey
Hello,
I am working or a ever increasingly complicated macro for the sole purpose
of discovering how much I don't know. I strike a new vein with each
session.
The macro find text and highlights it. I define an array of five color
options. That part was easy because I hacked some code Doug Robbins posted.
The problem was how to start with yellow and then move to red, then to teal,
etc. Here is the fruit of hair pulling:
I set the variable value at 0 on opening the document and in another macro
when all highlighting is cleared. Then the IF statement changes it to a 1
effectively bypassing the 0 position in the array. Yellow highlight is
applied to the found text. Next time around the ELSEIF makes the 1 a 2 and
Red highlight is applied, etc.
Is this how this should be done, or am I driving a tack with a sledge
hammer?
On Error Resume Next
pCcnt = ActiveDocument.Variables("pCcnt").Value
On Error GoTo 0
If pCcnt = 0 Then
pCcnt = 1
ElseIf pCcnt = 1 Then pCcnt = 2
ElseIf pCcnt = 2 Then pCcnt = 3
ElseIf pCcnt = 3 Then pCcnt = 4
ElseIf pCcnt = 4 Then pCcnt = 5
ElseIf pCcnt = 5 Then pCcnt = 1
End If
ActiveDocument.Variables("pCcnt").Value = pCcnt
pCycleCols = Array(wdNoHighlight, wdYellow, wdRed, wdTeal, wdPink,
wdTurquoise)
I am working or a ever increasingly complicated macro for the sole purpose
of discovering how much I don't know. I strike a new vein with each
session.
The macro find text and highlights it. I define an array of five color
options. That part was easy because I hacked some code Doug Robbins posted.
The problem was how to start with yellow and then move to red, then to teal,
etc. Here is the fruit of hair pulling:
I set the variable value at 0 on opening the document and in another macro
when all highlighting is cleared. Then the IF statement changes it to a 1
effectively bypassing the 0 position in the array. Yellow highlight is
applied to the found text. Next time around the ELSEIF makes the 1 a 2 and
Red highlight is applied, etc.
Is this how this should be done, or am I driving a tack with a sledge
hammer?
On Error Resume Next
pCcnt = ActiveDocument.Variables("pCcnt").Value
On Error GoTo 0
If pCcnt = 0 Then
pCcnt = 1
ElseIf pCcnt = 1 Then pCcnt = 2
ElseIf pCcnt = 2 Then pCcnt = 3
ElseIf pCcnt = 3 Then pCcnt = 4
ElseIf pCcnt = 4 Then pCcnt = 5
ElseIf pCcnt = 5 Then pCcnt = 1
End If
ActiveDocument.Variables("pCcnt").Value = pCcnt
pCycleCols = Array(wdNoHighlight, wdYellow, wdRed, wdTeal, wdPink,
wdTurquoise)