Quote Originally Posted by June7 View Post
I don't find any code in the Word document. How is this supposed to work?

Many will not download files from external location. Better to attach files directly to post. Can use Windows Compression and zip to one file for attachment.
I am sorry for not uploading the files in the post.

There is no code in that Word Document.

What I want to achieve is to use a Word macro to add hyperlinks according to an Excel file:

Step 1. allow users to browse and choose an Excel file (that Excel file contains column A (text) and column B (6-digit numbers))


strWB = BrowseForFile("Select Workbook", True)
strSheet = "URL"
If strWB = Empty Then
Exit Sub
Else

Private Function BrowseForFile(Optional strTitle As String, Optional bExcel As Boolean) As String
Dim fDialog As FileDialog
    On Error GoTo ERR_HANDLER
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .Title = strTitle
        .AllowMultiSelect = False
        .Filters.Clear
        If bExcel Then
            .Filters.add "Excel workbooks", "*.xls,*.xlsx,*.xlsm"
        Else
            .Filters.add "Word documents", "*.doc,*.docx,*.docm"
        End If
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then GoTo ERR_HANDLER:
        BrowseForFile = fDialog.SelectedItems.item(1)
    End With
lbl_Exit:
    Exit Function
ERR_HANDLER:
    BrowseForFile = vbNullString
    Resume lbl_Exit
End Function

2. Ask the user to input "Meeting ID" in the input box, e.g.:


  Dim mtgID As String
mtgID = InputBox("Input meeting ID。")
  If mtgID = Empty Then
    MsgBox "No meeting ID input。"
    Exit Sub
    Else


3. Find all 6-digit numbers (extract the column B of the selected Excel file)


I just know the code for Word, but i don't know how to edit it for Excel:


Dim aRng As Range
Set aRng = ActiveDocument.Range
  With aRng.Find
    .ClearFormatting
    .Text = "[0-9]{6}"
    .MatchWildcards = True


4. Calculate the start time

  Dim Hr As Integer
  Dim Mn As Integer
  Dim Sc As Integer
  Dim startTime As Long
 Do While .Execute
      Hr = CInt(Left(aRng.Text, 2))
      Mn = CInt(Mid(aRng.Text, 3, 2))
      Sc = CInt(Right(aRng.Text, 2))
      startTime = Hr * 3600 + Mn * 60 + Sc
 Loop
5. Add hyperlinks to the text in a Word Document, according to the selected Excel file

E.g.:
ActiveDocument.Hyperlinks.add Anchor:=aRng, Address:="https://ABC?meetingid=" & _
 mtgID & "&start=" & startTime
aRng.Collapse Direction:=wdCollapseEnd
Here's the original macro for using in Word Document:

Sub AddHyperlinksToTimeMarkers()
Dim mtgID As String, aRng As Range
Dim hrs As Integer, mins As Integer, secs As Integer, startTime As Long
mtgID = InputBox("Enter meeting ID")     ' Ask for meeting ID
' Find all six-digit numbers (time markers)
Set aRng = ActiveDocument.Range
With aRng.Find
    .ClearFormatting
    .Text = "[0-9]{6}"
    .MatchWildcards = True
    ' Loop through each time marker and add hyperlink
    Do While .Execute
      ' Get hours, minutes, and seconds from time marker
      hrs = CInt(Left(aRng.Text, 2))
      mins = CInt(Mid(aRng.Text, 4, 2))
      secs = CInt(Right(aRng.Text, 2))
      startTime = hrs * 3600 + mins * 60 + secs      ' Calculate starting time
      ' Add hyperlink to time marker
      ActiveDocument.Hyperlinks.Add Anchor:=aRng, Address:="https://ABC?meetingid=" & mtgID & "&start=" & startTime
      aRng.Collapse Direction:=wdCollapseEnd
    Loop
  End With
End Sub
Here are files for testing:
https://drive.google.com/drive/folde...i_?usp=sharing

My boss has requested me to add hyperlinks manually to more than 100 documents. May you please help me to solve the above issue? Many thanks in advance for your help! T^T (attached sample files for testing)


Thank you for your time and expertise, and I look forward to hearing from you soon.