Home > Software engineering >  Find the Word VBA in the selected text cycle
Find the Word VBA in the selected text cycle

Time:09-16

Sub test ()

X=Selection. End

The Do While Selection. The Find. The Execute (" ^ p ") And Selection. The Start & lt; X


N=n + 1

Loop

The Debug. Print n

End Sub

CodePudding user response:

All commented On the Error Resume Next statement, running in the VBA IDE,
The error and then click the debugging, the cursor will stop error in the statement,
Or
In doubt may have a logical error statements in advance to set breakpoints, run through the breakpoint interrupt,

At this point can be used in the immediate window
? The variable name
Or
? The function name () function parameter
Or
Process (parameters)
Auxiliary debugging,

CodePudding user response:

This macro can be achieved, in turn, find the ori () in the text, and replaced with the corresponding rep () the text in the
Ori=Array (" a ", "b", "c")
Rep=Array (" a ", "b", "c")
For I=0 To UBound (Ori)
With the Selection. The find
Text=Ori (I)
. Replacement. Text=Rep (I)
The Forward=True
The Wrap=wdFindContinue
Don't find the Format. The Format=False '
Case-insensitive. MatchCase=False '
Is not adopted. MatchWholeWord=False 'full word matching
. MatchByte=False 'does not distinguish between the half Angle
. MatchWildcards=False 'don't use a wildcard
. MatchSoundsLike=False 'don't find homophones
. MatchAllWordForms=False 'not find words all forms
End With




This macro can continue to search the full text of specific characters, and statistical number
I=1
Do
With the Selection. The find
. ClearFormatting
The Forward=True
The Wrap=wdFindContinue
. MatchWildcards=True
The Execute (Text="in the input the content of the need to find")
End With
If Selection. The find. Found Then
I=I + 1
The Else: Msgbox (" in the input the content of the need to find a total of "& amp; I & amp; "A")
End the If
Loop
  •  Tags:  
  • VBA
  • Related