Const scUserAgent = "API-Guide test program"
Const INTERNET_OPEN_TYPE_DIRECT = 1, INTERNET_OPEN_TYPE_PROXY = 3, INTERNET_FLAG_RELOAD = &H80000000
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Sub [B]test[/B]()
Dim hl As Hyperlink, sh As Worksheet: Set sh = ActiveSheet
Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
sBuffer = Space(1000) 'Create a buffer for the file we're going to download
'Create an internet connection
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
On Error GoTo er
[B]For Each hl In sh.Hyperlinks[/B]
[B]hl.Range.Interior.ColorIndex = 0[/B]
If hl.Address Like "http://*.*" Then
hFile = InternetOpenUrl(hOpen, hl.Address, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&) 'Open the url
InternetReadFile hFile, sBuffer, 1000, Ret 'Read the first 1000 bytes of the file
Debug.Print hl.Address, IIf(hFile <> 0, "available", "not valid")
[B][COLOR="Red"] hl.Range.Interior.Color = IIf(hFile <> 0, vbGreen, vbred)[/COLOR][/B]
InternetCloseHandle hFile: DoEvents
End If
[B]Next[/B]
er:
InternetCloseHandle hFile
InternetCloseHandle hOpen
End Sub
In Column A I have listed...
No.Could it be a firewall issue?
Could it be a firewall issue?
Try
Code:Const scUserAgent = "API-Guide test program" Const INTERNET_OPEN_TYPE_DIRECT = 1, INTERNET_OPEN_TYPE_PROXY = 3, INTERNET_FLAG_RELOAD = &H80000000 Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long Sub [B]test[/B]() Dim hl As Hyperlink, sh As Worksheet: Set sh = ActiveSheet Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long sBuffer = Space(1000) 'Create a buffer for the file we're going to download 'Create an internet connection hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0) On Error GoTo er [B]For Each hl In sh.Hyperlinks[/B] [B]hl.Range.Interior.ColorIndex = 0[/B] If hl.Address Like "http://*.*" Then hFile = InternetOpenUrl(hOpen, hl.Address, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&) 'Open the url InternetReadFile hFile, sBuffer, 1000, Ret 'Read the first 1000 bytes of the file Debug.Print hl.Address, IIf(hFile <> 0, "available", "not valid") [B][COLOR=Red] hl.Range.Interior.Color = IIf(hFile <> 0, vbGreen, vbred)[/COLOR][/B] InternetCloseHandle hFile: DoEvents End If [B]Next[/B] er: InternetCloseHandle hFile InternetCloseHandle hOpen End Sub
All of the available hyperlinks will be painted in green, not available - in red