+ Reply to Thread
Results 1 to 5 of 5

Checking Web Page(s) within a table.

Hybrid View

  1. #1
    Registered User
    Join Date
    09-19-2010
    Location
    USA, USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Checking Web Page(s) within a table.

    I'm having trouble trying to accomplish something specific, and I'd greatly appreciate any guidance available. I'm very "functionally proficient' in Excel, but am by NO means an advanced user or programmer.

    I have a list of web page URL's in a spreadsheet column. For example, A1:A100.

    I'd like to be able to tell whether or not a particular web page exists at each of the URL's in column A, with some kind of result appearing in each corresponding cell of Column B. I can be something as straightforward as a TRUE/FASLE, or even an ERROR/non ERROR would suffice.

    Is there a way for a relative novice to accomplish this?

    Thanks in advance for any guidance.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Checking Web Page(s) within a table.

    Create a Module Level object in the VBE and add the following and then run the macro "CheckURLExists"

    Sub CheckURLExists()
        Dim rCell As Range, stURL As String
    
        For Each rCell In ActiveSheet.Range("A1:A100")
            stURL = Trim(rCell.Value)
            If Len(stURL) > 0 Then
                If Not LCase(stURL) Like "http*" Then stURL = "http://" & stURL
                rCell.Offset(0, 1).Value = IIf(URLExists(stURL), "True", "False")
            End If
        Next rCell
    
    End Sub
    Function URLExists(stURL As String) As Boolean
        Dim oURL As Object
        Set oURL = CreateObject("MSXML2.XMLHTTP")
        oURL.Open "HEAD", stURL, False
        On Error Resume Next
        oURL.send
        URLExists = (oURL.Status = 200)
    End Function
    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,266

    Re: Checking Web Page(s) within a table.

    @Richard Buttrey: this looks really useful. Please could you step through the function and explain what you are doing. Thanks

  4. #4
    Registered User
    Join Date
    09-19-2010
    Location
    USA, USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Checking Web Page(s) within a table.

    Wow! That's absolutely terrific. Thank you for your elegant solution. Even *I* was able to put it in place. Could you please help me understand the meaning of the 200 status?

    This most certainly works, but apparently the test I was hoping to validate ultimately isn't based upon the presence of absence of a web page - as each URL ultimately returns a PDF file (or not). I though the "existence test" would work because when setting a cell's hyperlink property to the URL and then clicking on it, Excel would either open the PDF in Internet Explorer or present a message box that it was unable to open the URL.

    Thank you again for your expertise.

  5. #5
    Registered User
    Join Date
    09-19-2010
    Location
    USA, USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Checking Web Page(s) within a table.

    Richard,

    I've stepped through the code - and, much like Spanish, although I can't speak a word of it, I think I understand what's happening.

    Might I trouble you to perhaps help me complete the last step of the puzzle?

    What I'm essentially trying to do is query a list of URLs to determine whether or not corresponding data exists. Think of it in terms of a football team with player uniform numbers 1 through 20.

    I can query each player's information by a URL derived from his uniform number. I had presumed if no player wore #5, there'd be no web page about him. I was wrong. When I query uniform #5, I will indeed get the full bio page if there is such a player, but I will receive a default "no such player exists" web page if there's not.

    Using the Array and Looping structure you've provided, is there any way to quickly determine which page I'm seeing (i.e. a valid bio page - or a "no such player page")?

    I'm sorry if I'm inarticulate or this seems arcane. I greatly appreciate your help.

    Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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