Getting redirect destination from an xml .send url action

Oliver Dewar

Board Regular
Joined
Apr 17, 2011
Messages
201
Hi Guys.

I'm using the following code to work out if a link to a url is broken or not:

Code:
            strURL = Activecell.value 'this is the url to test
            Set objhttp = CreateObject("MSXML2.XMLHTTP")            
            objhttp.Open "HEAD", strUrl, False
            objhttp.send
        
            If objhttp.statusText <> "OK" Then
                Activecell.Interior.Color = 255
            End If

But sometimes it marks a link red (for broken) when in fact it's a redirect. I'm going to trap the 301 redirect statuses to handle those, however I sometimes encounter a status '0' and text 'Unknown' when there's a redirect (presumably a different kind to 301).

The only way I can come up with to programmatically test if a destination page of a '0' redirect is in fact OK or not is to find out what the destination url is then run keyword tests on it.

With that in mind I'd like to know how to return the destination url when using the above method (if possible).

I can achieve it with the:

Code:
         With IE
        .Visible = False
        .Navigate domain 'this is the url
        msgbox .LocationURL
        End With

method... but that involves reloading the url and would slow down the process a lot. It's a fall back... but if anyone knows a way to get the redirect destination from the original method I'd appreciate the tip :-)
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Found my answer - for those who may come after me down this little rabbit hole:

With MSXML2 I haven't worked out if you can get the location of the redirect... however with version 5.0 you can.

On this page: Check if URL exists, is so then return true

I found all my answers including how to get the location from a similar call to the one I was trying to use.

Kenneth Hobson knows his stuff. :smile:
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top