Checking validity of hyperlinks to HTTP files

P

Piotr Bieniek

Hello,

I would like to write a macro, which checks validity of all hyperlinks in a
document whenever this document is changed (saved). My macro works great
when links point to local files or network drives, but I don't know how to
check if there is a document at specified URL (http:// in my case). I check
whether files exist using FileSystemObject and it seems that it just does
not understand "http://" prefix. It always reports that file does not exist.

Can you help me? Do you find any solution of my problem? Any suggestions? I
thought I could use WinInet library, but AFAIK it is not possible in a
macro. Any other ideas?

Thanks in advance

Piotr Bieniek
 
M

Malcolm Smith

If you use the iNet control to go to the URL and to grab the document and
then when it finishes trap the DocumentComplete event and then see what is
in there.

Malc
www.dragondrop.com
 
P

Piotr Bieniek

If you use the iNet control to go to the URL and to grab the document and
then when it finishes trap the DocumentComplete event and then see what is
in there.

What is "iNet control"? How to use it? Could you provide any sample? I typed
"iNet control" in MSDN and unfortunetely, no results were found.

Piotr Bieniek
 
M

Malcolm Smith

It's the web browser control. Go into the control toolbar and right
click to get up "Additional Controls..." and then select the Microsoft
Internet Transfer Control.

Now, some code. Hang on. I've got some here when I was messing about
with scraping some web sites:

For example, shove the iNet control onto a form (it will be hidden) and
then in the code within the form you can call it by:


sHTML = cntInet.OpenURL(sURL)


The OpenURL() method opens the document at that URL. The contents are
returned to sHTML. Perhaps you could work on this to make sure that a
404 error is not found.


Alternately, you can mess about with the WebBrowser control.

Hope that this gets you going
Malc
www.dragondrop.com
 
P

Piotr Bieniek

Hello,
It's the web browser control. Go into the control toolbar and right
click to get up "Additional Controls..." and then select the Microsoft
Internet Transfer Control.

Do you remember that I was talking about MS Word Macro, not standalone
VB/C#/C++/whatever application? I'm afraid I cannot do it this way you
suggest. I do not have WebBrowser control embedded in my documents and I
can't see how could I create and use it from a macro. But, I'm quite
unexperienced in VBA scripts, so please correct me if I'm wrong.


Piotr Bieniek
 
M

Malcolm Smith

Piotr

It makes no difference if you use VBA or VB. All you do is to create a
form in the Word Template and then, in that form, drop the controls.

They both use the COM interface (how applications communicate with
external objects) so it makes no difference if you use VB, Word, Excel or
the like.

If you wand a start on how to put a form in a template then you could do
worse than look at http://www.dragondrop.com/wordcoding/word011a.asp which
will get you up and running.

If the form then contains the iNet or the WebBrowser control then that's
all you have to do. I drop all manner of controls into my Office
applications...

Hope that this helps
Malc
www.dragondrop.com
 
C

Chris Worth

there are two controls that you can use. The first is
the "Internet Control" which has been around forever.

set inetControl = Server.CreateObject("InetCtls.Inet")
inetControl.protocol = 4 'HTTP
inetControl.accesstype = 1 'Direct connection to
internet
inetControl.requesttimeout = 60 'in seconds
inetControl.URL = strURL
strHTML = Inet1.OpenURL
set inetControl = nothing

The second is MSXML, which I prefer. After you install
MSXML (goto msdn.microsoft.com/xml for it), it is pretty
easy to get the contents of a page.

url="http://www.microsoft.com"
Set objHTTP = CreateObject("MSXML4.XMLHTTP")
Call objHTTP.Open("GET", url, FALSE)
objHTTP.Send
textofpage = objHTTP.ResponseText
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top