Solved

check to see if website exists with vba

Posted on 2011-02-22
6
653 Views
Last Modified: 2012-05-11
I have an Excel workbook that pulls data from our intranet.  However, the URLs change and I am wondering if there is a way to loop through the URLS on the worksheet and return to the user an error message if any of them are broken - I want to do this before processing the data as there are 100's of URLs and if one fails, the user has to find it, fix it and start all over again.
0
Comment
Question by:ssmith94015
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:cdebel
ID: 34955853
There's plenty of applications doing this.   Any particular reason why you need to develop something for that?
0
 

Author Comment

by:ssmith94015
ID: 34955919
Because this is a customized VBA program and has to be internal to it.
0
 
LVL 10

Accepted Solution

by:
cdebel earned 500 total points
ID: 34956102
You can use this to check if it exist or not...

Function GetUrlStatus(argUrl)
    On Error Resume Next
    With CreateObject("msxml2.xmlhttp")
        .Open "GET", argUrl, False
        .send
        If Err Then
            GetUrlStatus = 9999 'to indicate server not found...
        Else
            GetUrlStatus = .Status
        End If
    End With
End Function
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:ssmith94015
ID: 34974740
Please note this question is NOT abandoned or forgotten, I got pulled to another project for an emergency, but will return to this question tomorrow!
0
 

Author Closing Comment

by:ssmith94015
ID: 34998603
This does work, next step is to figure out how to loop through the array, but progress!  Thank you for being patient as I know it took a while for me to get back to this question.
0
 
LVL 10

Expert Comment

by:cdebel
ID: 34999918
Well, not much informations were given about the array.
Let's say that you got your URL's into Column A of Sheet1.  You could have this piece of code to check for the broken links, and set the status for every sites in Column B...

If you can give me more precision, i'll help.

Public Sub VerifyAllUrls()
    Dim sURL As String
    
    For Each cel In Sheet1.UsedRange.Rows.EntireRow
        sURL = cel.Cells(1, 1)
        cel.Cells(1, 2).Value = IIf(GetUrlStatus(sURL) <> 9999, "OK", "BROKEN")
    Next
    Sheet1.Columns.AutoFit
End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now