问题
I have a webquery within a macro.
.Refresh BackgroundQuery:=False
The above line puts the webpage contents in the active worksheet. Then I find a string "approved" with the code given below
Set findRng = Cells.Find(What:="approved", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If the string is found, I do some job with the code given below
If Not findRng Is Nothing Then
'do some job
End If
Can I find the word approved
directly from memory or some kind of array without putting the contents of the webpage in the sheet and if yes, how?
回答1:
Function GetResponseText(url as String) as String
Dim objHttp As Object
objHttp = CreateObject("MSXML2.ServerXMLHTTP")
objHttp.Open("GET", url, False)
objHttp.Send("")
GetResponseText = objHttp.ResponseText
End Function
GetResponseText contains the html as text (full scripting) search with:
If instr(GetResponseText([your url]), "approved") > 1 Then
'your code if approved
Else
'your code if not
End If
you may check the string of 'GetResponseText' and search for ">approved<" or something like that
来源:https://stackoverflow.com/questions/33417502/find-a-string-in-web-query-without-putting-webpage-contents-on-the-sheet