Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-10-2013, 11:18 PM
fumei fumei is offline Copy paste highlighted text to another doc Windows 7 64bit Copy paste highlighted text to another doc Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

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.
Reply With Quote
  #2  
Old 04-10-2022, 09:43 AM
burniksapwet burniksapwet is offline Copy paste highlighted text to another doc Windows 10 Copy paste highlighted text to another doc 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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Text Twice to Paste into word Albundy Word 2 09-02-2016 12:59 PM
Copy paste highlighted text to another doc Find & selected paras with highlighted text & copy to clipboard marceepoo Word VBA 1 09-14-2012 08:20 PM
Copy paste highlighted text to another doc Table copy/paste suddenly text-only mjcoon Word Tables 20 04-28-2012 08:53 PM
Can't copy/cut and paste text in Word 2002 mmiller751 Word 0 04-17-2012 02:55 PM
Losing Text box data when copy and paste Spay Excel 0 03-15-2011 07:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft