D
Designingsally
i m attempting to write macro where it checks for "A" in the style (heading
2). This style can be found in the Home table under Styles group. The macros
I have got searches for the word "A" in the entire document, which is wrong.
Is there a same way to arrive at the solution.
The macros I have attempted is shown below:
Sub FindHeading()
Dim oRng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
Selection.Style = ActiveDocument.Styles("Heading 2")
If Not Selection.Style = ActiveDocument.Styles("Heading 2") Then
Exit Sub
sFindText = "a" 'Replace to find
With Selection
..HomeKey wdStory
With .FInd
'.ClearFormatting
'.Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = True
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set oRng = Selection.Range
sRep = Msgbox("change the word")
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
oRng.Text = sRepText
End If
Wend
End With
End With
End If
End Sub
2). This style can be found in the Home table under Styles group. The macros
I have got searches for the word "A" in the entire document, which is wrong.
Is there a same way to arrive at the solution.
The macros I have attempted is shown below:
Sub FindHeading()
Dim oRng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
Selection.Style = ActiveDocument.Styles("Heading 2")
If Not Selection.Style = ActiveDocument.Styles("Heading 2") Then
Exit Sub
sFindText = "a" 'Replace to find
With Selection
..HomeKey wdStory
With .FInd
'.ClearFormatting
'.Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = True
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set oRng = Selection.Range
sRep = Msgbox("change the word")
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
oRng.Text = sRepText
End If
Wend
End With
End With
End If
End Sub