• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Find Redirect URL

coolkiran

Member
Hello Everyone

I have a webaddress around 1,000 in column, everything is 302 (Redirecting to another website). IS there any way to find the redirecting website address in Excel. Because I have code,
Code:
Function redirect_url(surl As String) As String

Dim myIE As Object
Set myIE = CreateObject("InternetExplorer.Application")
myIE.Navigate surl
Do While myIE.busy
Loop
redirect_url = myIE.Document.URL
myIE.Quit
Set myIE = Nothing

End Function
This is ok for 1-10 urls, if its more than 1000, it will take a day to find web address.

Any suggestion?
 
Pls check this..

Code:
Option Explicit

Public Function Rurl(ByVal url As String)
Dim http As Object
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
    http.Option(WinHttpRequestOption_UserAgentString) = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
    http.Option(WinHttpRequestOption_EnableRedirects) = False
       
    If Not InStr(url, "://") > 0 Then url = "http://" & url
   
    http.Open "GET", url
    http.Send
    Rurl = http.GetResponseHeader("Location")
Set http = Nothing
End Function
 
Try this as didn't encounter any issue so far!!!

Screenshot 2014-08-08 10.23.50.png

Code:
Option Explicit

Public Function Rurl(ByVal url As String)
Dim http As New WinHttpRequest
    http.Option(WinHttpRequestOption_UserAgentString) = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
    http.Option(WinHttpRequestOption_EnableRedirects) = False
       
    If Not InStr(url, "://") > 0 Then url = "http://" & url
   
    http.Open "GET", url
    http.Send
    Rurl = http.GetResponseHeader("Location")
End Function
 
Back
Top