View Single Post
 
Old 10-12-2025, 02:48 AM
chrisjj chrisjj is offline Windows 7 64bit Office 97-2003
Competent Performer
 
Join Date: Aug 2025
Posts: 135
chrisjj is on a distinguished road
Default

That's great. Thanks very much

I've enhanced to wildcard match:

Code:
Sub Macro1()
Dim oRng As Range
Dim sFind As String
Dim sAddr As String
Dim sPath As String
    sFind = "\((X[0-9]{5})\)"
    Set oRng = ActiveDocument.Range
    With oRng.Find
        .MatchWildcards = True
        Do While .Execute(sFind)
            'sAddr = oRng.Text
            sAddr = "???"
            sPath = "folder\file " & sAddr & ".txt" 'assemble the link path
            Debug.Print sPath
            oRng.Hyperlinks.Add oRng, sPath, , , oRng.Text
            oRng.End = oRng.Hyperlinks(1).Range.End
            oRng.Collapse 0
        Loop
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
but cannot find how to set sAddr to the first captured expression e.g. X12345. Any idea?

Attached.
Attached Files
File Type: doc LinkAutoGen test.doc (23.5 KB, 1 views)
Reply With Quote