Create a program the checks all the links in your web page whether they are active or not.

原创 2002年03月11日 09:19:00
Create a program the checks all the links in your web page whether they are active or not.
By S.S. Ahmed

This article will show you how to test your web page for the active links. You will learn how to use the Internet Transfer Control. This is a real world example of inet usage. 
  VB, XP, W2K, Win9X
  Posted 12 Nov 2001
  Updated 13 Nov 2001
hlp.gif Articles by this author
mail.gif Send to a friend
print.gif Printer friendly version
Views: 1,693   [This is an unedited reader contribution] [Modify this article] [Delete this article]
What's New
Message Boards
6 users have rated this article. result:
red.gif red.gif red.gifwhite.gif white.gif white.gif
2.33 out of 5.

Sample Image - linkchecker.jpg


In this article I will show you how to create a program that checks whether the links in your web application are active or not. We will use Internet Transfer Control to accomplish this task. This is a real world example where you will see the real use of Internet Transfer Control.

About the application:

Internet Transfer Control is a very handy control. The program will check each link in the web page to see if it’s functioning or not. Suppose, I add web page addresses of different people on my web page, now the web pages usually move to different locations or people simply put their sites off the internet, and all of a sudden my links are dead. If I have more than 100 links on my page, then to check all those pages manually will be a hectic task and we can’t check the URLs on a regular basis. So, we need to automate this process. An easy way is to keep a links database either in Access or in Excel and then check all the links in the database whether they are functioning. You can populate your web page with the live links from your database.

What this program does?

The program we are going to create will perform the following tasks:

1. The program would open a worksheet.
2. It would use OLE Automation to read the first URL and see whether it’s functioning.
3. Write data back to the worksheet, indicating the result for the URL.
4. Repeat the preceding steps for all the URLs in the list.
5. Save and close the worksheet.

What is OLE?

OLE stands for Object Linking and Embedding. It is a technology for transferring and sharing information among applications. Different applications expose their objects that are related to the kind of data the application works with. Automation client is an application that exposed objects belonging to another application. In our case, our VB program will act as an Automation client. An Automation server is an application that exposes programmable objects to other applications. In our case, Excel will act as an Automation server. Excel exposes Automation objects. These objects have properties and methods as their external interface. Properties are named attributes of the Automation object. Methods are functions that work on an Automation object.

More about the application

Let's discuss the layout of the Excel worksheet in the data will be stored. When the program has completed the task, each record in the Excel worksheet will contain an entry specifying the current status of the URL. The application will run minimized in the background while your other applications work normally. The number of links already checked is displayed in the program's title bar and therefore also displayed on the taskbar icon when the program is minimized. This enables the user to keep track of the progress. When the URLs have been checked, the program closes the worksheet and displays a summary report.

URL will be saved in column C, the third cell from the left, and the information as to whether the link is okay is kept in column E. Data begins in row 4.

I have included detailed comments in the code so that you can see how it works. You will have to edit the code before running it. Change the path of the Excel file in the code. 

'Save the filename in a variable

Const FILE = "C:/hrd_links.xls" (This variable should contain the exact path of the file)

Here is the complete code of the application:

'Create the Excel object

Set objExcel = CreateObject("Excel.Application")

'Open the worksheet
objExcel.Workbooks.Open MYFILE

'Set the Transfer Protocol
Inet1.Protocol = icHTTP

'This is the main function!!
Public Sub Check_Links()

'This function will be called to check all the links in the

'Declare variables
Dim var_row As Integer
Dim var_URL As String
Dim var_buffer As String
Dim var_msg As String
Dim var_file_not_found As Integer
Dim var_server_not_found As Integer
Dim var_timeout As Integer
Dim var_OK As Integer

'Catch the time-out errors

On Error Resume Next

'Set the row variable to the cell where the data starts
var_row = STARTROW

'Initialize the variables

var_timeout = 0
var_file_not_found = 0
var_OK = 0
var_server_not_found = 0

'Minimize the form
frmmain.WindowState = 1

'Loop through all the URLs
    'Get the URL
    var_URL = objExcel.Cells(var_row, URL_COL)

    'Check whether the first cell is empty
    If var_URL = "" Then Exit Do

    'Open the URL
    Text1.Text = Inet1.OpenURL(var_URL)

    'Avoid tying up the system

    'Errors messages are found in the  first 50 characters
    'returned by the openurl method

    If Len(Text1.Text) > 50 Then

        var_buffer = Left(Text1.Text, 50)


        var_buffer = Text1.Text

    End If

    'Catch a time-out error

    If Err = 35761 Then
         var_msg = "Timed Out"
         var_timeout = var_timeout + 1

	'If nothing is returned, it means that the server was
        'not found

    ElseIf Text1.Text = "" Then

        var_msg = "Server not found"
        var_server_not_found = var_server_not_found + 1

        'If error 404 is returned from the URL, it means the
       'server was found but he file was not found

    ElseIf InStr(1, var_buffer, "404") Then

        var_msg = "File not found"
       var_file_not_found = var_file_not_found + 1

    'else, the link is OK


        var_msg = "OK"
        var_OK = var_OK + 1

    End If

    'Save the result back to the worksheet

    objExcel.Cells(var_row, STATUS) = var_msg

    'Move to the next row

    var_row = var_row + 1

    'Display the current status.

    frmmain.Caption = var_OK + var_file_not_found + var_server_not_found + var_timeout

    'Display the results on the form

    Label1.Caption = "OK: " & var_OK
    Label2.Caption = "File not found: " & var_file_not_found
    Label3.Caption = "Server not found: " & var_server_not_found
    Label4.Caption = "Timed out: " & var_timeout

Loop While True

'If all the links have been checked, restore the form

frmmain.WindowState = 0

'Close the Worksheet


'Remove the object from the memory
Set objExcel = Nothing

'Display the results

var_buffer = "OK: " & var_OK & vbCrLf
var_buffer = var_buffer & "Server not found: " & var_server_not_found & vbCrLf
var_buffer = var_buffer & "File not found: " & var_file_not_found & vbCrLf
var_buffer = var_buffer & "Timed out: " & var_timeout

MsgBox var_buffer

Open the Excel workbook and add the links you want the program to check. Close the workbook and run the program. Make sure you are connected to the internet. That’s it.

About S.S. Ahmed

S.S. Ahmed is a senior software engineer and works for a web and software development firm. Ahmed specializes in creating database driven dynamic web sites. He uses ASP and VB for most of what he develops. Ahmed likes to hop into other tools as well. Ahmed has worked in Assembly language, C, C++, FoxPro, QBasic, All version of Visual Basic (currently experimenting with VB.NET), Visual C, Java, ASP, etc. Ahmed enjoys travelling and has been to many parts of the world. Ahmed can be reached at

安装oracle 11g过程中,prerequisite checks过程中各种failed问题解决

问题一:Packages报错 yum环境配置好后,就可以运行yum install packagename命令进行包的安装  yum install compat-libstdc++-33  el...
  • benbenzhuhwp
  • benbenzhuhwp
  • 2015年04月12日 20:37
  • 2915

Environment variable: "PATH" - This test checks whether the length of the environment variable "PATH

Oracle11G win7安装,之前有过安装,可能没有卸载gank
  • wodestudy
  • wodestudy
  • 2014年04月18日 09:48
  • 12008

LightOJ 1214 - Large Division (大数求余)

1214 - Large Division Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...
  • helloiamclh
  • helloiamclh
  • 2016年01月13日 17:16
  • 649

zabbix 小问题解决汇总

问题一:server端和agentd端报错找不到以下host zabbix_server.log  26214:20161117:143243.773 cannot send list of acti...
  • qq_33588470
  • qq_33588470
  • 2016年11月17日 15:39
  • 4595

Sorry, your browser / program is not supported by Web Dynpro

Sorry, your browser / program is not supported by Web Dynpro
  • champaignwolf
  • champaignwolf
  • 2017年10月30日 09:38
  • 458

Light oj 1214 Large Division(同余定理,判断是否整除)

Description Given two integers, a and b, you should check whether a is divisible by b or not. We kn...
  • baidu_35522092
  • baidu_35522092
  • 2016年08月29日 14:26
  • 577

zabbix客户端日志报错no active checks on server []: host [] not found

zabbix客户端日志报错: 45647:20160808:220507.717 no active checks on server []: host [19...
  • reblue520
  • reblue520
  • 2016年08月10日 12:40
  • 9455

LIGHTOJ-1214 - Large Division

1214 - Large Division PDF (English) Statistics Forum Time Limit: 1 sec...
  • nvliba
  • nvliba
  • 2015年12月04日 15:56
  • 1076

HDU 2161 Primes (判断素数的水题)

U - Primes HDU - 2161  Write a program to read in a list of integers and determine whether or not ...
  • qq_41444888
  • qq_41444888
  • 2018年01月05日 20:47
  • 33

J2EE学习从菜鸟变大鸟之七 Servlet

J2EE学习从菜鸟变大鸟之七 Servlet 原创 2014年03月05日 23:32:24 标签: 4148 编辑 删除     Servlet现在自己...
  • yegshun
  • yegshun
  • 2018年01月22日 10:03
  • 11
您举报文章:Create a program the checks all the links in your web page whether they are active or not.