Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-16-2023, 08:19 AM
yanyan9896 yanyan9896 is offline Simple issues about adding hyperlinks Windows 10 Simple issues about adding hyperlinks Office 2019
Novice
Simple issues about adding hyperlinks
 
Join Date: Oct 2023
Posts: 13
yanyan9896 is on a distinguished road
Smile Simple issues about adding hyperlinks

Hello,



I would like to make some modifications to the macro discussed in my previous post (refer to the URL: https://www.msofficeforums.com/word-...six-digit.html). The updated macro should have the ability to perform the following tasks:

1. Using the following code to browse and choose the Excel file (the Excel file contains column A (text) and column B (6-digit numbers)


Code:
Dim EXL As Object
Dim xlsWB As Object
Dim xlsPath As String


Set EXL = CreateObject("Excel.Application")

    xlsPath = BrowseForFile("Select Workbook", True)
    If Not xlsPath = vbNullString Then
        Set xlsWB = EXL.Workbooks.Open(xlsPath)



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. Extract 6-digit numbers from selected Excel file's column B into the macro


Code:

'I don't know how to write this part. Here's the code for Extracting 6-digit numbers from Word for your references.


With aRng.Find
    .ClearFormatting
    .Text = "[0-9]{6}"
    .MatchWildcards = True
3. Use the following code to calculate start time



Code:

  Dim Hr As Integer
  Dim Mn As Integer
  Dim Sc As Integer
  Dim startTime As Long


    Do While .Execute
      ' Get hours, minutes, and seconds from time marker
      hrs = CInt(Left(aRng.Text, 2))
      mins = CInt(Mid(aRng.Text, 3, 2))
      secs = CInt(Right(aRng.Text, 2))
      startTime = hrs * 3600 + mins * 60 + secs
4. Enter the meeting ID for merging the link



Code:

Dim mtgID As String


mtgID = InputBox

If mtgID = Empty Then
Exit Sub
5. Add hyperlinks to the names according to selected Excel file's column A



Code:
      ActiveDocument.Hyperlinks.Add Anchor:=aRng, Address:="https://ABC?meetingid=" & mtgID & "&start=" & startTime
      aRng.Collapse Direction:=wdCollapseEnd
    Loop
  End With
End Sub
Those names' format are as follows:


Code:
    With Selection.Find
        .Font.Name = "Times New Roman"
        .Font.Size = 14
        .Font.BOLD = True
        .MatchWildcards = True
Here are the demo files for testing:


1. Word Document (contain Names)
Word Document.docx


2. Excel file (contain column A(Names) and column B (6-digit numbers)
Excel file.xlsx



Prior to conducting my research, I sought advice from experienced VBA experts who suggested a solution. According to their recommendation, I can incorporate a numbered bookmark for each item found. This approach enables the retrieval of the calculated start time in seconds, which can then be assigned back to the corresponding hyperlinks associated with each bookmark. But I am still new to VBA and I am not fully understand that.



I would like to express my gratitude in advance to anyone who can provide assistance in editing the macro. Thank you!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple issues about adding hyperlinks VBA Macro issue: Adding Hyperlinks to six-digit numbers yanyan9896 Word VBA 5 10-08-2023 04:19 AM
Adding Hyperlinks (more than 1) to a BIG picture Word Smith Word 3 08-23-2022 04:01 PM
Simple issues about adding hyperlinks Adding PreserveFormatOnUpdate to macro that updates all hyperlinks within a document JellehFishh Word VBA 5 03-17-2020 02:47 PM
Issues with transferring files with hyperlinks. Help with a solution? tay Excel 0 02-20-2015 07:28 AM
Hyperlinks get messed when adding or deleting some slides? Learner7 PowerPoint 0 05-17-2010 04:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft