Select highlighted text
SolvedAlain 06 Posted messages 69 Registration date Status Membre Last intervention -
Hello everyone.
I am using Word 2016 and Windows 10.
In a Word document, I have highlighted paragraphs that I export to another blank document using the command Find -> Advanced Find -> Format -> Highlight -> Look in -> main doc -> Close (as soon as the selection is complete) -> Ctrl+c -> open the new document -> Ctrl+V
Perfect result.
I do the same manipulation with the macro recorder and I get the runtime error code 4605 with the message "This method or property is not available because no text has been selected.
My question:
Where is my mistake?
What does Text and Replacement.Text do?
It is Selection.Copy that is causing the problem.
If anyone has an idea, I would appreciate it, best regards.
Here is the code obtained with the recorder:
Sub ExportTxtSurligne()
'
' ExportTxtSurligne Macro
' Searches for highlighted text, selects it, copies it; opens new doc, pastes it.
'
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
With Selection.Find
.Text = ""
.Replacement.Text = "^pServices :"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.Paste
Selection.HomeKey Unit:=wdStory
End Sub
2 réponses
Hello
Since you mentioned in an alert that you solved the problem yourself, it would be nice of you to share the solution with us.
This could, who knows, help other internet users facing this type of issue.
Thank you in advance for them.
Very difficult to catch a black cat in a dark room.
Especially when it's not there...
Oh nothing could be simpler, go to Search -> Advanced search -> Format -> Highlighting -> Search in -> main doc -> Close (as soon as the selection is finished) -> Ctrl+c -> open the new document -> Ctrl+V
Perfect result.
It takes a bit of time, but much less than waiting for a hypothetical response.
Thank you for your message, this discussion is resolved.