View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Williams Tim Williams is offline
external usenet poster
 
Posts: 1,588
Default Detecting Internet Site

http://www.tech-archive.net/Archive/.../msg00560.html

Function Fetch(xURL)
On Error Resume Next
Err.Clear
Dim objXML
Set objXML = CreateObject("Microsoft.XMLHTTP")
objXML.Open "HEAD",xURL,False
objXML.Send
If Err.Number < 0 Then
Fetch = "Error# " & Err.Number
Else
Fetch = "Status " & objXML.Status
End If
Fetch = Fetch & " : " & xURL
Set objXML = Nothing
End Function

Tim

"J Streger" wrote in message
...
I am writing code to go out to a sharepoint and grab files from the
sharepoint. I have encountered lots of issues as my workplace doesn't have
that handy .ocx library that has the ability to detect if files exist on
the
internet. I cannot install 3rd party applications or use anything that
isn't
in the general system ghost.

So I was hoping there would be a Windows API call that could detect if a
file/website exists. Currently I have the following (which I grabbed
partially from another site). It detects if a file exists at a website,
but
if the website doesn't exist it just creates the file and returns 1 saying
the file exists:

Public Function InternetFileExists(sPath As String) As Long

Dim HTML As HTMLDocument
Dim tHTML As HTMLDocument
Dim lRet As Long

On Error GoTo CATCHERROR

'Create new HTML Doc
Set tHTML = New HTMLDocument

'Create a document from the URL Path
Set HTML = tHTML.createDocumentFromUrl(sPath, vbNullString)

'wait for the document to load
Do While HTML.readyState < "complete"
DoEvents
Loop

'Test to see if a 404 or similar error is found
If InStr(1, LCase(HTML.body.innerText), "not found") 0 Then
lRet = 0
Else
lRet = 1
End If

QUICKEXIT:

InternetFileExists = lRet

'Clear Variables
Set HTML = Nothing
Set tHTML = Nothing

Exit Function

CATCHERROR:

lRet = -1
Resume QUICKEXIT

End Function 'InternetFileExists

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

User of MS Office 2003