Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-10-2024, 08:08 AM
syl3786 syl3786 is offline Word Macro issue: Change text color with track changes record Windows 10 Word Macro issue: Change text color with track changes record Office 2019
Advanced Beginner
Word Macro issue: Change text color with track changes record
 
Join Date: Jan 2023
Posts: 78
syl3786 is on a distinguished road
Unhappy Word Macro issue: Change text color with track changes record

Hello everyone,



I was hoping to get some assistance with an issue I'm having in a Word Document. I have a macro that changes text from wdred to wdblack, but I would like the changes to be tracked so that I can easily identify which parts of the document have been modified. I tried adding "ActiveDocument.TrackRevisions = True" at the beginning of the code, but unfortunately it's not working as expected. Although the text color is changing correctly, I'm unable to identify which parts of the document have been modified, as the document is quite large (200 pages).

Here's the code I'm currently using:

Code:
Sub Macro1()

    Selection.Find.ClearFormatting
    Selection.Find.Font.Color = wdColorRed
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Color = wdColorBlack
    With Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Would anyone be willing to assist with this issue? I would greatly appreciate any help or suggestions you may have. Thank you!


Remarks:

My computer:

Windows 10
Microsoft Office 2019
i7-8700
8 GB Ram
Reply With Quote
  #2  
Old 01-10-2024, 08:37 AM
vivka vivka is offline Word Macro issue: Change text color with track changes record Windows 7 64bit Word Macro issue: Change text color with track changes record Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi! Try using
Code:
    ActiveDocument.TrackRevisions = Not ActiveDocument.TrackRevisions
Reply With Quote
  #3  
Old 01-10-2024, 09:21 AM
Charles Kenyon Charles Kenyon is offline Word Macro issue: Change text color with track changes record Windows 11 Word Macro issue: Change text color with track changes record Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Cross-posted at:How to find all text in wdRed and then change to wdBlack, with track changes? - Eileen's Lounge
For cross-posting etiquette, please read: A Message to Forum Cross-Posters
Reply With Quote
  #4  
Old 01-10-2024, 05:04 PM
Guessed's Avatar
Guessed Guessed is offline Word Macro issue: Change text color with track changes record Windows 10 Word Macro issue: Change text color with track changes record Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The Execute ReplaceAll command doesn't track the formatting change so you need to loop that step.
Code:
Sub Macro1()
  Dim aRng As Range, aRng2 As Range
  ActiveDocument.TrackRevisions = True
  ActiveDocument.TrackFormatting = True
  
  Set aRng = Selection.Range
  Set aRng2 = aRng.Duplicate
  With aRng.Find
    .ClearFormatting
    .Font.Color = wdColorRed
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchByte = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    Do While .Execute = True
      aRng.Font.ColorIndex = wdBlack
      aRng.End = aRng2.End
    Loop
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 01-10-2024, 05:46 PM
syl3786 syl3786 is offline Word Macro issue: Change text color with track changes record Windows 10 Word Macro issue: Change text color with track changes record Office 2019
Advanced Beginner
Word Macro issue: Change text color with track changes record
 
Join Date: Jan 2023
Posts: 78
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
The Execute ReplaceAll command doesn't track the formatting change so you need to loop that step.
Code:
Sub Macro1()
  Dim aRng As Range, aRng2 As Range
  ActiveDocument.TrackRevisions = True
  ActiveDocument.TrackFormatting = True
  
  Set aRng = Selection.Range
  Set aRng2 = aRng.Duplicate
  With aRng.Find
    .ClearFormatting
    .Font.Color = wdColorRed
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchByte = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    Do While .Execute = True
      aRng.Font.ColorIndex = wdBlack
      aRng.End = aRng2.End
    Loop
  End With
End Sub
I want to express my deep gratitude for your assistance! The solution you provided has proven to be effective!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Macro issue: Change text color with track changes record Word 16/19 change font and outside border color (same color) eg is red change to pink jec1 Word VBA 2 12-04-2019 11:32 PM
Macro to change an RGB table cell shading color to another RGB color David Matthews Word VBA 4 05-29-2018 02:45 PM
Word Macro issue: Change text color with track changes record Macro in Word to track colour of highlighted text BABZ Word VBA 1 01-09-2017 10:33 PM
Word Macro issue: Change text color with track changes record Macro to change all text color to black in all docx files in a selected folder joewoods Word VBA 13 05-16-2016 06:29 PM
Word macro doesn't change font color Spideriffic Word VBA 8 11-04-2015 03:47 AM

Other Forums: Access Forums

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