Thank you Russ. That worked. I have another shape macro that I use. The
problem is when I run the findPCN macro it will only find the first
occurrence in each case. Is there a better way to write my first macro so I
can use periodic’s findit macro?
Sub PCNHighlight()
Dim idx As Long
Dim PCN As Shape
Dim i
On Error GoTo endthis
i = Selection.Information(wdVerticalPositionRelativeToPage)
Select Case Selection.Style
Case ActiveDocument.Styles(wdStyleHeading1)
Set PCN = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 48, i - 3, 32,
18#)
PCN.Fill.ForeColor.RGB = RGB(150, 150, 150)
PCN.Fill.Transparency = 0.3
PCN.Line.Visible = msoFalse
PCN.Name = "PCNa" & idx
idx = idx + 1
Case ActiveDocument.Styles(wdStyleHeading2)
Set PCN = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 48, i - 3, 32,
18#)
PCN.Fill.ForeColor.RGB = RGB(150, 150, 150)
PCN.Fill.Transparency = 0.3
PCN.Line.Visible = msoFalse
PCN.Name = "PCNb" & idx
idx = idx + 1
Case ActiveDocument.Styles(wdStyleHeading3)
Set PCN = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 85, i - 3, 40,
18#)
PCN.Fill.ForeColor.RGB = RGB(150, 150, 150)
PCN.Fill.Transparency = 0.3
PCN.Line.Visible = msoFalse
PCN.Name = "PCNc" & idx
idx = idx + 1
Case ActiveDocument.Styles(wdStyleHeading4)
Set PCN = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 129, i - 3, 25,
18#)
PCN.Fill.ForeColor.RGB = RGB(150, 150, 150)
PCN.Fill.Transparency = 0.3
PCN.Line.Visible = msoFalse
PCN.Name = "PCNd" & idx
idx = idx + 1
Case ActiveDocument.Styles(wdStyleHeading5)
Set PCN = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 153, i - 3, 25,
18#)
PCN.Fill.ForeColor.RGB = RGB(150, 150, 150)
PCN.Fill.Transparency = 0.3
PCN.Line.Visible = msoFalse
PCN.Name = "PCNe" & idx
idx = idx + 1
Case ActiveDocument.Styles(wdStyleHeading6)
Set PCN = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 174, i - 3, 25,
18#)
PCN.Fill.ForeColor.RGB = RGB(150, 150, 150)
PCN.Fill.Transparency = 0.3
PCN.Line.Visible = msoFalse
PCN.Name = "PCNf" & idx
idx = idx + 1
Case ActiveDocument.Styles(wdStyleHeading7)
Set PCN = ActiveDocument.Shapes.AddShape(msoShapeRectangle, 199, i - 3, 25,
18#)
PCN.Fill.ForeColor.RGB = RGB(150, 150, 150)
PCN.Fill.Transparency = 0.3
PCN.Line.Visible = msoFalse
PCN.Name = "PCNg" & idx
idx = idx + 1
endthis:
End Select
End Sub
periodic’s findit macro
Sub findPCN()
Selection.HomeKey unit:=wdStory, Extend:=wdMove
Dim elm As Shape
For Each elm In ActiveDocument.Shapes
If InStr(1, elm.Name, "PCN", vbTextCompare) Then
elm.Select
gotoRange rng:=Selection.Range
elm.Select
MsgBox prompt:="See the next PCN Number"
End If
Next elm
End Sub