Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-26-2014, 03:17 AM
tarktran tarktran is offline Macro to find coloured text and replace with form-field/formtext containing that text Windows 7 64bit Macro to find coloured text and replace with form-field/formtext containing that text Office 2010 64bit
Novice
Macro to find coloured text and replace with form-field/formtext containing that text
 
Join Date: Nov 2014
Posts: 1
tarktran is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 11-26-2014, 08:12 AM
gmayor's Avatar
gmayor gmayor is offline Macro to find coloured text and replace with form-field/formtext containing that text Windows 7 64bit Macro to find coloured text and replace with form-field/formtext containing that text Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
Reply

Tags
formtext, macro, textform



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to find coloured text and replace with form-field/formtext containing that text Macro to find text and replace with form field containing that text iiiiifffff Word VBA 16 06-04-2016 01:47 AM
Macro to find coloured text and replace with form-field/formtext containing that text 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
Macro to find coloured text and replace with form-field/formtext containing that text 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:44 PM.


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