Steve001
Board Regular
- Joined
- Apr 13, 2017
- Messages
- 91
- Office Version
- 365
- 2021
- 2013
- Platform
- Windows
Hello All,
I wish to modify the macro that is in this post
www.mrexcel.com
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
This code works fantastic, i have come across an older document that is set as follows:
Reference Type: Numbered Item
Insert Reference to: Paragraph Number
The above code changes these to
Reference Type: Heading
Insert Reference to: Heading Text
Can you please advise what to change
I am using office 363 & office 2021
Regards
Steve
I wish to modify the macro that is in this post

Word VBA Macro
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'...
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
This code works fantastic, i have come across an older document that is set as follows:
Reference Type: Numbered Item
Insert Reference to: Paragraph Number
The above code changes these to
Reference Type: Heading
Insert Reference to: Heading Text
Can you please advise what to change
I am using office 363 & office 2021
Regards
Steve