vba macro to unhighlight all highlights

Anonymous
2021-06-30T17:31:05+00:00

Hello,

I am struggling with getting some vba code to achieve our goal of unhighlighting all highlights in a Word document.

I can get as far as unhighlighting the body of the document and headers until there is a section break, then the headers/footers do not get updated.

Is there a way to achieve removing all the highlights regardless of where in the document they are?

Sub unHighLight()

Dim StoryRange As Range

For Each StoryRange In ActiveDocument.StoryRanges

StoryRange.HighlightColorIndex = wdNoHighlight 

Next StoryRange

End If

End Sub

Regards,

ScoGu

[ Moderator: edited code to format as code and delete End If with no If. Also gave macro a name.]

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

7 answers

Sort by: Most helpful
  1. Stefan Blom 345.4K Reputation points MVP Volunteer Moderator
    2021-06-30T23:28:41+00:00

    On Graham Mayor's site, there is some sample code for processing all "story ranges" of a document. Below is a slight modification of that code.

    The modified macro loops through all story ranges (the main body, headers, footers, text boxes) of the current document and sets the Text Highlight Color to "No color."

    Sub RemoveTextHighlightColorAllDoc()

    'Macro created by Stefan Blom, June 2021

    'Original code by Graham Mayor at

    'http://www.gmayor.com/installing_macro.htm

    Dim oStory As Range

    For Each oStory In ActiveDocument.StoryRanges

    oStory.HighlightColorIndex = wdNoHighlight

    If oStory.StoryType <> wdMainTextStory Then

    While Not (oStory.NextStoryRange Is Nothing)

    Set oStory = oStory.NextStoryRange

    oStory.HighlightColorIndex = wdNoHighlight

    Wend

    End If

    Next oStory

    lbl_Exit:

    Set oStory = Nothing

    Exit Sub

    End Sub

    Was this answer helpful?

    3 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2021-07-01T14:25:20+00:00

    Thank you Stefan Blom! and Graham Mayor

    This is what I was looking for. I very much appreciate your assistance!

    Was this answer helpful?

    0 comments No comments
  3. Charles Kenyon 168.3K Reputation points Volunteer Moderator
    2021-06-30T23:03:04+00:00

    I am a volunteer. I do not really care to spend my time reproducing problem documents so I can talk to people about them. I suspect others here are more generous with their time. I wish you luck.

    What you are requesting is NOT something that is built into Word with an easy solution. It will likely require or best be accomplished with a macro.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2021-06-30T22:54:58+00:00

    Thanks for your response Charles,

    Organizational rules prevent sharing links or using Dropbox.

    I hope some screenshots showing the issue can help highlight the NotHighlight issue.

    Here is a screenshot of example document, Before running macro code. Top split shows a section break for title page. Allowing for Header to start on page 2-end of document.

    After macro code is ran, the screenshot below shows how the body of all pages have had the highlighting removed, but the headers have not had the highlighting removed.

    There is intentional shading/fill in some places that we do not want altered, only the highlighting update to NotHighlight. But would like it to be done throughout the document including all headers.

    With shading/fill example before:

    After code above applied (currently keeps shading/fill as intended):

    Was this answer helpful?

    0 comments No comments
  5. Charles Kenyon 168.3K Reputation points Volunteer Moderator
    2021-06-30T17:38:56+00:00

    I modified your code posting a bit.

    I do not know if the document you are working on has shading rather than highlighting applied.

    Please post a sample document where you are seeing the problem to assist in troubleshooting.

    Why a sample file is important for troubleshooting. How to do it.

    Was this answer helpful?

    0 comments No comments