Additional text to hyperlink text does not extend the hyperlink style
Test file https://1drv.ms/u/s!AviK4OVgysDigfoU...5vgXw?e=xatcnV
Code below was adapted a little from that supplied on another forum by Macropod, whom I notice is in this forum also, so might be familiar with this code.
Attached is the test document. Basically this stage of markup of the file (which is processed by another app) I am trying to markup Bible chapter and verse numbers. The example shows just the chapter:verse. This needs a Book name which in this case I have set to Matthew in the code below. All you need to do to test is to select a couple of paragraphs in whole and run the code.
This with hyperlink text
22:4. The king reiterates the honor of the invitation.
22:5. Ignoring the king would be scandalously rude, .....
22:6. This behavior would obviously have .....
becomes this. Which has not extended the hyperlink text to include Matthew
Matthew 22:4. The king reiterates the honor of the invitation.
Matthew 22:5. Ignoring the king would be scandalously rude, .....
Matthew 22:6. This behavior would obviously have .....
The next stage that might be required in some cases is to markup this text, but the macro that is specifically designed for this part does not like the mixed, plain text and hypelink text.
So my question is, how to code this to "extend" the hyperlink text so it Includes Matthew.
Thanks to anyone who can help
Jon.
Code:
Sub testforforum()
Dim prefix As String
prefix = "Matthew" 'InputBox("Please enter the Bible book Name")
'If ComboBox1BibleBookName.text = "" Then
' MsgBox ("Please set a Bible book from the ComboBox")
' Exit Sub
'End If
'InSelection = False
'If selection.Type = wdSelectionIP Then InSelection = True
'
'If InSelection = True Then
'
' MsgBox ("select some text")
' Exit Sub
'End If
Application.ScreenUpdating = False
Dim RngFnd As Range, StrTxt As String
'If CheckBox3PrefixChVerseAnywhereInSelection.Value = False Then
'####################################
With selection
Set RngFnd = .Range
With .Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.text = "[0-9]{1,3}:[0-9\-\–:]{1,9}"
.Replacement.text = ""
.Forward = True
.Format = False
.Wrap = wdFindStop
.MatchWildcards = True
'Required font size and color can be set here
.Font.Size = 10 'ComboBox2FontSize.Value
'.Font.Color = 12611584
.Execute
End With
Do While .Find.Found
If .InRange(RngFnd) Then
If .Paragraphs.Count > 1 Then .Start = .Paragraphs(1).Range.End
If .Start = .Paragraphs(1).Range.Start Then
.Font.Size = ComboBox2FontSize.Value
StrTxt = .text
.InsertBefore prefix & " "
'If CheckBox4Bold.Value = True Then
.Font.Bold = True
' End If
'If CheckBox5Blue.Value = True Then
.Font.ColorIndex = wdBlue
'End If
.Start = .End - Len(StrTxt)
End If
If .Hyperlinks.Count > 0 Then
If .Hyperlinks(1).Range.Start = .Paragraphs(1).Range.Start Then
With .Hyperlinks(1).Range
.Font.Size = 10 'ComboBox2FontSize.Value
StrTxt = .text
.InsertBefore prefix & " "
'If CheckBox4Bold.Value = True Then
.Font.Bold = True
'End If
'If CheckBox5Blue.Value = True Then
.Font.ColorIndex = wdBlue
'End If
.Start = .End - Len(StrTxt) - 1
End With
End If
End If
Else
Exit Do
End If
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
End With
RngFnd.Select
Application.ScreenUpdating = True
selection.Find.ClearFormatting
selection.Find.Replacement.ClearFormatting
End Sub