Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-04-2023, 08:04 PM
bblelli bblelli is offline Find the content by color and copy it Windows 10 Find the content by color and copy it Office 2021
Novice
Find the content by color and copy it
 
Join Date: Feb 2023
Posts: 22
bblelli is on a distinguished road
Angry Find the content by color and copy it

Dears,

I'm trying to create a macro that search for every text written in purple color and
everytime the macro finds this red text, the macro should copy this paragrah and the next one.

Let's suppose that I have the following text:

Add Value. Something many self-made wealthy people have in common is that they are valuable in specific ways. ...
Tax Yourself. The concept of saving money is not a new one. ...


Create a Plan and Follow It. ...
Invest. ...
Start a Business. ...
Be Grateful. ...
Develop Patience. ...

In this case, I would like to have another word document with the following content:
Tax Yourself. The concept of saving money is not a new one. ...
Create a Plan and Follow It. ...

How can I do that?

I'm trying to work with the following code, wchich is working and returning just the first line, not the second one.

Code:
Option Explicit

Sub CopyRedText()
    Dim oTarget As Document
    Dim oDoc As Document
    Dim oRng As Range, oEnd As Range, oOriginal As Range
    Set oDoc = ActiveDocument
    Set oTarget = Documents.Add
    Set oRng = oDoc.Range
    Set oOriginal = oDoc.Range
    Set oEnd = oTarget.Range
    oOriginal.Collapse 0
    With oRng.Find
    .Font.Color = RGB(112, 48, 160)
    
        Do While .Execute
            If oRng.Start >= oOriginal.Start Then GoTo lbl_Exit
            oEnd.Collapse 0
            

            oEnd.FormattedText = oRng.FormattedText

            
            oEnd.Collapse 0
            oEnd.Collapse 1
            oEnd.InsertParagraphAfter
            oEnd.End = oTarget.Range.End
            'oRng.Text = ""
            'oRng.Collapse 0
        Loop
    End With
    oTarget.Activate
lbl_Exit:
    Exit Sub
End Sub
Thanks
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy/paste changes text color !!! yvessr Word 8 07-16-2019 02:44 PM
Content control font color rkferguson Word VBA 1 12-18-2018 05:06 AM
Find the content by color and copy it Changing color of instructional text in a content control box Document Specialist Word 2 08-17-2018 05:25 AM
Find the content by color and copy it Text Field [content control] - Default text color vs Filled Text color jackcoletti Word 3 02-01-2017 08:10 AM
Find the content by color and copy it Macro that can find phrase and then find another and copy jperez84 Word VBA 10 09-19-2012 04:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:46 PM.


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