![]() |
#1
|
|||
|
|||
![]()
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 |
|
![]() |
||||
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 |
![]() |
Document Specialist | Word | 2 | 08-17-2018 05:25 AM |
![]() |
jackcoletti | Word | 3 | 02-01-2017 08:10 AM |
![]() |
jperez84 | Word VBA | 10 | 09-19-2012 04:48 PM |