forked from farishadi/Excel_Macro_References
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchForHTML
More file actions
36 lines (29 loc) · 1.15 KB
/
SearchForHTML
File metadata and controls
36 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Public Function HTMLSearchFor(ByRef oPage As Object, ByRef sSearchText As String, Optional iSearchCat As Integer = 1) As Object
'this function looks for the HTML document elements needed
'function allows approximate matching via flipping the iSearchCat switch
'(1 for ID matching, 2 for Tag Name matching)
Dim dErrTime As Date
On Error GoTo errHandlerHTMLSearch
dErrTime = Now()
If iSearchCat = 1 Then
Set HTMLSearchFor = oPage.Document.getElementById(sSearchText)
ElseIf iSearchCat = 2 Then
Set HTMLSearchFor = oPage.Document.getElementsByTagName(sSearchText)
End If
Exit Function
errHandlerHTMLSearch:
'type mismatch error from HTMLSearchFor, looking for data while waiting for page is loading
'used as a makeshift do while/application wait, end if looped more than a minute
'Err.Raise (Err.Number)
Err.Number = 0
If Now() >= dErrTime + TimeValue("00:01:00") Then
If sSearchText = "QUICKSEARCH_TABLE" Then
Set HTMLSearchFor = Nothing
Exit Function
Else
MsgBox "Macro stuck in infinite loop. Please retry macro. If problem persists, contact macro creator.", vbExclamation, "ERROR!"
End
End If
End If
Resume
End Function