View Single Post
 
Old 01-03-2022, 10:45 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If each item in the list is a paragraph then select the list and run the following Word macro. This will hyperlink those paragraphs that have valid folder paths. Invalid paths are coloured red.

Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 04 Jan 2022
Dim sLink As String
Dim oLink As Hyperlink
Dim oPara As Paragraph
Dim oRng As Range
Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    For Each oPara In Selection.Paragraphs
        Set oRng = oPara.Range
        oRng.End = oRng.End - 1
        If FSO.FolderExists(oRng.Text) Then
            Set oLink = Selection.Hyperlinks.Add(Anchor:=oRng, _
                                                      Address:=oRng.Text, _
                                                      ScreenTip:="Click to select the linked folder", _
                                                      TextToDisplay:=oRng.Text)
        Else
            oRng.Font.ColorIndex = wdRed
        End If
    Next oPara
lbl_Exit:
    Set oLink = Nothing
    Set oRng = Nothing
    Set oPara = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote