Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-23-2022, 04:50 PM
JamesKenwood JamesKenwood is offline Tagging Highlighted text with appropriate color Mac OS X Tagging Highlighted text with appropriate color Office 2021
Novice
Tagging Highlighted text with appropriate color
 
Join Date: Nov 2022
Posts: 3
JamesKenwood is on a distinguished road
Default Tagging Highlighted text with appropriate color

I am pretty new to VBA so am trying to find my feet to do a task but can't find a sample anywhere to achieve this.



I need to find all highlighted text in a given colour (lets say yellow for now but will want to do blue too) then tag that text with "[color:yellow]" and [/color]. So I can maintain that information on export to another format.

So far I have the following, but it has problems.
1. I need to run it multiple times to find each highlight, I just want it to process whole document
2. It doesn't find the yellow highlight on lines that have blue and yellow highlights (so highlighting individual words not a whole paragraph)
3. The end tag goes onto the following line

Any guidance would be so much appreciated...

Code:
Sub Highlighting()
    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .MatchWildcards = False
        .Forward = True
        .Wrap = wdFindContinue
        .Highlight = True
        Do
        .Execute
          Loop Until Selection.Range.HighlightColorIndex = wdYellow _
          Or Not .Found
            Selection.Range.InsertBefore "[Color: Yellow ]"
            Selection.Range.InsertAfter "[/Color]"
    End With
End Sub
Reply With Quote
 

Tags
highlight, highlight color



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tagging Highlighted text with appropriate color Text Field [content control] - Default text color vs Filled Text color jackcoletti Word 3 02-01-2017 08:10 AM
Tagging Highlighted text with appropriate color Cannot see highlighted text for moving text in a do ument Jonfrank1@me.com Project 1 01-09-2017 06:04 PM
Tagging Highlighted text with appropriate color I need to convert shaded text into highlighted text on about 80 different long documents. VBA macro? AustinBrister Word VBA 8 05-28-2015 02:42 PM
Tagging Highlighted text with appropriate color Formatting- Apply changes to highlighted text results in same change to other text sential Word 6 01-10-2014 03:22 PM
Macro for tagging and rearranging selected text for revision caotico Word VBA 0 03-28-2012 06:35 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft