Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-16-2017, 12:30 PM
Mcoon Mcoon is offline Select Red text and Delete Windows 10 Select Red text and Delete Office 2016
Novice
Select Red text and Delete
 
Join Date: Feb 2017
Posts: 2
Mcoon is on a distinguished road
Default Select Red text and Delete

Hello all,



I am trying to create a macro that will select any red text in a document and then delete it, but I am having trouble doing so.

There are multiple types of formatting in this document (some is smaller font or italicized, etc) that use red text and I want to select/delete them all.

I have been looking online for hours and trying to figure it out myself, but I am new to VBA and I am not getting very far.

Any help would be much appreciated. Thanks!

Windows 10
Office 2016
Reply With Quote
  #2  
Old 02-16-2017, 01:44 PM
macropod's Avatar
macropod macropod is offline Select Red text and Delete Windows 7 64bit Select Red text and Delete Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You don't need a macro for this - it can all be done via a single Find/Replace. Simply set the Find parameter for the font colour to 'red'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-16-2017, 01:54 PM
Souriane Souriane is offline Select Red text and Delete Windows 7 64bit Select Red text and Delete Office 2013
Advanced Beginner
 
Join Date: Feb 2017
Location: Quebec, Canada
Posts: 82
Souriane is on a distinguished road
Default

Hi!

Try this :

Code:
Sub ReplaceRed()
'
    With Selection.Find
       .ClearFormatting
       .Font.Color = wdColorRed
       .Replacement.ClearFormatting
       .Text = ""
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = True
 
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    
End Sub
Souriane
Reply With Quote
  #4  
Old 02-16-2017, 02:38 PM
Mcoon Mcoon is offline Select Red text and Delete Windows 10 Select Red text and Delete Office 2016
Novice
Select Red text and Delete
 
Join Date: Feb 2017
Posts: 2
Mcoon is on a distinguished road
Default

Thank you so much for your quick reply!

Just solved my problem.

Also, I know it could be done via find/replace, but I want to incorporate this routine into a larger macro that does many different things at once.

Thanks for all the help!
Reply With Quote
  #5  
Old 02-16-2017, 09:41 PM
macropod's Avatar
macropod macropod is offline Select Red text and Delete Windows 7 64bit Select Red text and Delete Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Mcoon View Post
I know it could be done via find/replace, but I want to incorporate this routine into a larger macro that does many different things at once.
In that case, the macro recorder would have given you all the code you needed - that's basically all the macro posted by Souriane is.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Red text and Delete After putting a text box behind text I can't select it anymore Mike84bs Word 2 07-25-2016 07:36 AM
How to select the text of certain length? gn4619 Word VBA 6 04-30-2015 12:56 PM
VBA Search Table for Text/Select Text/Insert Hyperlink sldrellich Word VBA 3 03-24-2015 01:09 PM
Microsoft Word macro to find text, select all text between brackets, and delete helal1990 Word VBA 4 02-05-2015 03:52 PM
Select Red text and Delete Select section of text and change text newbieX Word VBA 3 03-28-2014 04:21 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:42 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