On Error GoTo ErrHandler
Dim objShellWins As SHDocVw.ShellWindows
Dim objIE As SHDocVw.InternetExplorer
Dim objDoc As Object
Dim i As Integer
Dim strOut As String
Dim intFree As Integer
Dim clsDialog As CDialog
Const URL_TO_SEARCH = "
http://www.mvps.org/access"Const ANCHOR_DESC_TO_SEARCH = "Comprehensive Links"
Set objShellWins = New SHDocVw.ShellWindows
For Each objIE In objShellWins
With objIE
If (InStr(1, _
.LocationURL, _
URL_TO_SEARCH, vbTextCompare)) Then
Set objDoc = .Document
If (TypeOf objDoc Is HTMLDocument) Then
OLECMDID_SAVEAS, _
OLECMDEXECOPT_PROMPTUSER)
Set clsDialog = New CDialog
With clsDialog
.hWnd = hWndAccessApp
.StartDir = CurDir
.ModeOpen = False
.DefaultExtension = "htm"
.Title = "Please select a folder to save the file"
.Filter = "HTML Files (*.htm, *.html)|*.htm"
strOut = .Action
End With
If Len(strOut) Then
intFree = FreeFile
Open strOut For Output As #intFree
Write #intFree, objDoc.body.parentElement.innerHTML
Close #intFree
With objDoc.all
For i = 1 To .Length
If (TypeOf .Item(i) Is HTMLAnchorElement) Then
If .Item(i).nodeName = "A" Then
If (InStr(1, _
.Item(i).innerText, _
ANCHOR_DESC_TO_SEARCH, _
vbTextCompare)) Then
Debug.Print objDoc.all.Item(i).href
Exit For
End If
End If
End If
Next
End With
End If
End If
Exit For
End If
End With
Next
ExitHere:
On Error Resume Next
Close #intFree
Set clsDialog = Nothing
Set objDoc = Nothing
Set objIE = Nothing
Set objShellWins = Nothing
Exit Sub
ErrHandler:
With Err
MsgBox "Error: " & .Number & vbCrLf & .Description, _
vbCritical Or vbOKOnly, .Source
End With
Resume ExitHere
End Sub