Excel URL Validation for secured HTTP authenticated Website

Avinesh

New Member
Joined
Jun 9, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi I was trying to validate a secured website using the URL in the following format https://username:password@host. When I run the site in browser it login and load the page automatically. But if I use =CheckURL(A1) in excel it says "The URL is invalid". Can someone help me with this please

This is the VBA code I use for validation

VBA Code:
Public Function CheckURL(url As String)
    Dim request As Object
    Set request = CreateObject("Winhttp.WinhttpRequest.5.1")
    On Error GoTo haveError
    With request
    .Open "HEAD", url
    .Send
    CheckURL = .Status & ": " & .statustext
    End With
    Exit Function
haveError:
    CheckURL = Err.Number & ": " & Err.Description
    End Function
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I suspect (though haven't checked), that to do it that way, you'll need to pass the "Basic Authentication" credentials in the Authorization header - rather than the url.

To check is, does this work? - in case it's not obvious, you'll need to extract the username and password

VBA Code:
Public Function CheckURL(url As String)
    Dim request As Object
    Set request = CreateObject("MSXML.XMLHTTP")
    On Error GoTo haveError
    With request
    .Open "HEAD", url, false, "username", "password"
    .Send
    CheckURL = .Status & ": " & .statustext
    End With
    Exit Function
haveError:
    CheckURL = Err.Number & ": " & Err.Description
    End Function
 
Upvote 0
Hi Kyle123, Thank you so much for your quick response. When I add the code and tried =CheckURL(A1) it say "#VALUE!" and not the status code
 
Upvote 0
You need to step through it, not just enter it as a formula
This is my first time using VBA and I have no idea on this. Can you explain in detail or share some article/video if possible. Thank you so much Kyle.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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