Word VBA Macro

Steve001

Board Regular
Joined
Apr 13, 2017
Messages
83
Office Version
  1. 365
  2. 2021
  3. 2013
Platform
  1. Windows
Hello,

I am not familiar with macros in word but have used them in excel quite a bit...
Is it possible to look through a word document for hyper links these are mainly from 'insert cross reference' then do the following ....

Some of these can be inside tables from 'insert table function'

check if it has an underline
underline if not

check the colour
set to dark blue if not

PS. Please put comments in the code so i can understand

I am using office 363 & office 2021

Regards
Steve
 
For that, you could use a macro like:
VBA Code:
Sub RefColorizer()
Application.ScreenUpdating = False
Dim Fld As Field, StrTxt As String
With ActiveDocument
  For Each Fld In .Fields
    With Fld
      If .Type = wdFieldRef Then
        StrTxt = Trim(.Code.Text)
        If InStr(StrTxt, "\h") > 0 Then
          StrTxt = "REF " & Split(StrTxt, " ")(1) & " \* Charformat \h"
          .Code.Text = StrTxt: .Code.Font.Underline = True: .Code.Font.ColorIndex = wdBlue
        End If
      End If
    End With
  Next
  .Fields.Update
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Thank you, i will try this monday and get back to you

Steve
 
Upvote 0

Forum statistics

Threads
1,226,114
Messages
6,189,051
Members
453,522
Latest member
Seeker2025

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top