+ Reply to Thread
Results 1 to 4 of 4

Test External Hyperlinks

Hybrid View

  1. #1
    Registered User
    Join Date
    10-26-2020
    Location
    NJ, USA
    MS-Off Ver
    Office 365
    Posts
    2

    Test External Hyperlinks

    Hello,

    I want to test external hyperlinks, that when they are broken color the cell yellow. I have this code but it seem to only work with an internal network

    Sub TestHLinkValidity()
    Dim rRng As Range
    Dim fsoFSO As Object
    Dim strFullPath As String

    Dim strPath As String
    Dim strFName As String
    Dim cCell As Range
    Dim response
    Dim intSlashCount As Integer

    Set fsoFSO = CreateObject("Scripting.FileSystemObject")
    Set rRng = Selection
    For Each cCell In rRng.Cells
    If cCell.Hyperlinks.Count > 0 Then
    strPath = GetHlinkAddr(cCell)
    If fsoFSO.FileExists(strPath) = False Then
    cCell.Interior.Color = 65535
    End If
    End If
    Next cCell
    End Sub

    Function GetHlinkAddr(rngHlinkCell As Range)
    GetHlinkAddr = rngHlinkCell.Hyperlinks(1).Address
    End Function

    Thanks
    Jeff

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Test External Hyperlinks

    Assuming external link always contain "http" in hyperlink.address.

    May be something like...
    Sub Demo()
    Dim rng As Range
    Dim cel As Range
    
    With Sheets("Sheet1")
        Set rng = .Range("A2:A" & .Cells(Rows.Count, "A").End(xlUp).Row)
    End With
    
    For Each cel In rng.Cells
        If cel.Hyperlinks.Count > 0 And InStr(cel.Hyperlinks(1).Address, "http") Then
            With CreateObject("MSXML2.ServerXMLHTTP")
                .Open "GET", cel.Hyperlinks(1).Address, False
                .send
                If .Status = 200 Then
                Else
                  cel.Interior.Color = 65535
                End If
            End With
        ElseIf cel.Hyperlinks.Count > 0 Then
            'Do something for local file link.
        End If
    Next
    End Sub
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    10-26-2020
    Location
    NJ, USA
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Test External Hyperlinks

    Thanks. Got a RT ERROR 9
    subscript out of range

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Test External Hyperlinks

    At which line of the code?

    That usually means some object isn't found. By any chance are you using Mac?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Test for invalid Hyperlinks
    By jdurbin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-14-2017, 12:33 PM
  2. [SOLVED] Test Hyperlinks to files on Network Drive
    By joe.cross in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-18-2016, 08:34 PM
  3. Automatically Test Hyperlinks in Excel 2007
    By Learner22 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-14-2012, 06:39 AM
  4. Automatically Test Hyperlinks in Excel 2007
    By friedboudinball in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-01-2012, 05:02 AM
  5. maintain hyperlinks with external links
    By nisbett in forum Excel General
    Replies: 0
    Last Post: 10-06-2011, 06:32 PM
  6. Capturing hyperlinks from external site
    By nobleprince in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-06-2010, 05:00 PM
  7. How can I test whether or not an external file exists?
    By WilliamCRodgers in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2009, 06:59 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1