A family of Microsoft word processing software products for creating web, email, and print documents.
Sorry - change the name of the second macro to FindPreviousOccurrence
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello from Steve
Objective please is to copy text and then find the second occurrence, using Sendkeys.
meaning SendKeys "{Find}" or similar.
For example
GRACIE THE CAT
copy the above and now find the second occurrence
GRACIE THE CAT
I thank you
A family of Microsoft word processing software products for creating web, email, and print documents.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
Sorry - change the name of the second macro to FindPreviousOccurrence
Answer accepted by question author
Does this do what you want? Select the text you want to find, then run the macro.
Sub FindNextOccurrence()
Dim s As String
s = Selection.Text
Selection.Collapse Direction:=wdCollapseEnd
Selection.Find.Execute FindText:=s, Forward:=True
End Sub
Hello HansV
Before I posted I changed Forward:=True to Forward:=False
I am getting
Compile error
Ambiguous name detected: FindNextOccurence
Sub FindNextOccurrence()
Dim s As String
s = Selection.Text
Selection.Collapse Direction:=wdCollapseStart
Selection.Find.Execute FindText:=s, Forward:=False
End Sub
Like this:
Sub FindNextOccurrence()
Dim s As String
s = Selection.Text
Selection.Collapse Direction:=wdCollapseStart
Selection.Find.Execute FindText:=s, Forward:=False
End Sub
Hello HansV
Yes that is what I am looking for.
Request please is it possible to search up.
All the Best
Steve