Check if URL exists, is so then return true

sdoppke

Well-known Member
Joined
Jun 10, 2010
Messages
647
Hi everyone, Im hoping someone can help me write a function (or mabe a macro?) that will check if a URL exists. If it does, would like it to return true and if it does not, then false. So I can tie the function to a cell, and have the cell return text for either answer.


Sounds pretty simple, but really stumped me. Everything i find in the forum shows how to open the URL. (dont need that).

thanks everyone in advance :)

sd
 
Well, for kicks try:
Code:
    With Request
      .Open "GET", url, False
      .Send
      rc = .StatusText
      [COLOR="Red"]msgbox .StatusText[/COLOR]
    End With

See if we're getting through ...
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Well, for kicks try:
Code:
    With Request
      .Open "GET", url, False
      .Send
      rc = .StatusText
      [COLOR=red]msgbox .StatusText[/COLOR]
    End With

See if we're getting through ...


Comes back, unauthorized... hmmmmmmm. I can open the file though?

sd
 
Upvote 0
I would guess it's a matter of how you authenticate yourself to the sharepoint server - possibly your browser uses an authentication method that the vba code doesn't. But I'm guessing. I really don't know much about sharepoint. It's certainly not a surprising result - though not one you want to get here.
 
Upvote 0
I don't use sharepoint but you could try:
Code:
MsgBox Dir("http://Directory1/Directory2/Directory3/File.xlsx")
if empty, the file does not exist. If not empty, the file was found.
 
Upvote 0
I have uses this code:

Function Test_URLExists() Dim url As String url = "http://www.mrexcel.com/forum/showthread.php?t=567315" MsgBox url, vbInformation, URLExists(url) url = "http://xwww.mrexcel.com/forum/showthread.php?t=567315" MsgBox url, vbInformation, URLExists(url)End FunctionFunction URLExists(url As String) As Boolean Dim Request As Object Dim ff As Integer Dim rc As Variant On Error GoTo EndNow Set Request = CreateObject("WinHttp.WinHttpRequest.5.1") With Request .Open "GET", url, False .Send rc = .StatusText End With Set Request = Nothing If rc = "OK" Then URLExists = True Exit FunctionEndNow:End Function</pre>

yes ive used this macro and formula and it works
you just have to change the formula to where your data is
so i have in the formula =urlexisits(A1&B1&C1)
 
Last edited:
Upvote 0
not sure if it was answered, your excel returns false due to authorization issue.
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

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