View Single Post
 
Old 04-10-2022, 09:43 AM
burniksapwet burniksapwet is offline Windows 10 Office 2007
Novice
 
Join Date: Jan 2022
Posts: 6
burniksapwet is on a distinguished road
Default

Quote:
Originally Posted by fumei View Post
Code:
Sub CopyHighlightsToOtherDoc()
Dim ThisDoc As Document
Dim ThatDoc As Document
Dim r As Range
Set ThisDoc = ActiveDocument
Set r = ThisDoc.Range
Set ThatDoc = Documents.Add
With r.Find
   .Text = ""
   .Highlight = True
   Do While .Execute(Forward:=True) = True
      ThatDoc.Range.InsertAfter r.Text & vbCrLf
      r.Collapse 0
   Loop
End With
End Sub

All highlighted text in the ActiveDocument are copied (with an added paragraph mark to separate them) to a new document.

This is awesome. But I was wondering if you can tweak this for my need. Basically it does the same thing but instead of pasting it in a new document I want it to override the current document. I want nothing else on that document but for the result to be pasted, then save it. This is so that I can keep the result under the same filename.
Thank you.
Reply With Quote