Find a string in web query without putting webpage contents on the sheet

a 夏天 提交于 2019-12-11 12:24:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!