|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Macro to find coloured text and replace with form-field/formtext containing that text
Hi,
I am trying to do the following (whether it can be manually done OR done using VBA), please note I only have a real basic understanding of VBA. What I am trying to achieve is: 1.) Search all text in the colour RED; 2.) Replace ALL text that appears in the colour RED and insert them in a {FORMTEXT} / textform while maintaining the text colour if possible. Or alternatively if that is not possible: 1.) Search for the word "cash" and; 2.) Replace it with a FORMTEXT with the text inserted to them If I can visibly see in the VBA code where the adjustments are required if I need to change the keyword to for example "month" then at least I can easily amend the code. Much appreciation to whomever views this thread and can help me out with a solution. Thanks, Tark |
#2
|
||||
|
||||
The following should find red text in the document body and put it in a text form field. The colour will be the underlying style colour.
Code:
Dim oRng As Range Dim strText As String Dim oFld As FormField Set oRng = ActiveDocument.Range With oRng.Find .ClearFormatting .Font.Color = wdColorRed .Replacement.ClearFormatting Do While .Execute(Forward:=True) = True strText = oRng.Text oRng.Text = vbNullString Set oFld = ActiveDocument.FormFields.Add(oRng, wdFieldFormTextInput) oFld.Result = strText Loop End With ActiveDocument.Protect _ Type:=wdAllowOnlyFormFields, _ NoReset:=True, _ Password:=""
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
formtext, macro, textform |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to find text and replace with form field containing that text | iiiiifffff | Word VBA | 16 | 06-04-2016 01:47 AM |
Word VBA Macro to Find and Replace based on the Alt Text of an Image | bennymc | Word VBA | 1 | 01-27-2014 04:23 PM |
Find & Replace: substitute red-coloured words with underscores | tinfanide | Word | 2 | 10-06-2012 11:04 PM |
Macro to populate a text form field based on dropdown selection | koloa | Word | 0 | 10-20-2011 11:52 AM |
Macro to mark non-coloured/non-highlighted text as hidden | PeterB | Word | 0 | 10-28-2009 07:54 AM |