Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

Excel Web Query II (Zvonko)

Here you helped me with a web query a couple weeks ago:


I would like to pull the following information off of this site:


I need to get into a cell using the same method you showed me before:

Average option volume
Average option open interest
IV index call (current)
IV index call (52 week high)
IV index call (52 week low)
IV index put (current)
IV index put (52 week high)
IV index put (52 week low)

now i tried to do it i used the yahoo page pretty well, the <$> eyecatcher just isn't working with this site.

Can you see if you can get it to pull this information?

  • 2
1 Solution
ZvonkoSystems architectCommented:

The problem is that you can not nominate the content by eye catcher but by cell number.

I have tested the new functionality with this Excel content:
A1: http://www.ivolatility.com/options.j?ticker=blud&R=0&top_lookup__is__sent=1
B1: 172
C1: 173
D1: 202
E1: 205
F1: 206
G1: 208
H1: 211
I1: 212

Here the code:

Sub getURLdata()
Dim nextURL As String
Dim webResponse As String
Dim nextCell As String
Dim i As Integer
Dim j As Integer
   For i = 1 To 3
       nextURL = Cells(i, 1).Value
       If (nextURL = "") Then Exit For
       webResponse = GetWebContent(nextURL, "", "")
       If (webResponse > "") Then
          For j = 2 To 12
             nextCell = Cells(i, j).Value
             If (nextCell = "") Then Exit For
             MsgBox ExtractCellData(webResponse, CInt(nextCell))
       End If
End Sub

Function GetWebContent(ByVal URL As String, ByVal UserID As String, ByVal Password As String) As String
  Dim uid As Variant
  Dim pwd As Variant
  Dim xml As Variant
  uid = UserID
  pwd = Password
  Set xml = CreateObject("Microsoft.XMLHTTP")
  Call xml.Open("GET", URL, False, uid, pwd)
  Call xml.Send
  GetWebContent = xml.responseText
End Function
Function ExtractCellData(ByVal textArea As String, ByVal cellNumber As Integer) As String
Dim i As Integer
Dim nextPos As Integer
Dim theCell As String
Dim inTag As Boolean
Dim nextChar As String

    nextPos = 1
    For i = 1 To cellNumber
      nextPos = InStr(nextPos, textArea, "<td") + 3
    theCell = Mid$(textArea, nextPos, InStr(nextPos, textArea, "</td") - nextPos)
    inTag = True
    For i = 1 To Len(theCell)
       nextChar = Mid$(theCell, i, 1)
       If (nextChar = ">") Then
          inTag = False
       ElseIf (nextChar = "<") Then
           inTag = True
       ElseIf (Not inTag) Then
           ExtractCellData = ExtractCellData + nextChar
       End If
    nextPos = InStr(ExtractCellData, "&nbsp;")
    Do While (nextPos > 0)
       If (nextPos > 1) Then
        ExtractCellData = Left$(ExtractCellData, nextPos - 1) & _
        Mid$(ExtractCellData, nextPos + 6)
        ExtractCellData = Mid$(ExtractCellData, 6)
       End If
       nextPos = InStr(ExtractCellData, "&nbsp;")
End Function

Good luck,

ZvonkoSystems architectCommented:
Please increase the dimension of nextPos from Integer to Long.

Like this:
  Dim nextPos As Long


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now