If I run this code from within the VBA IDE, e.g. press F5 on the Test
routine, my connection and parsing the xml happens almost instantly.
Sub Test()
Sheet1.Range("4:20000").Clear
Dim con As New msxml2.ServerXMLHTTP60
con.Open "GET", "mySite", False, "username", "password"
con.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
con.send
Dim xmlDoc As msxml2.DOMDocument60
Set xmlDoc = con.responseXML
parseXmlDoc xmlDoc
End Sub
Private Sub parseXmlDoc(xmlDoc As msxml2.DOMDocument60)
Dim r As Integer: r = 3
Dim c As Integer: c = 0
Dim oo As Object
Dim pp As Object
Dim qq As Object
On Error GoTo ErrHandle
With Sheet1
Set oo = xmlDoc.SelectNodes("root/myNode")
For Each pp In oo
r = r + 1
For Each qq In pp.ChildNodes
c = c + 1
.Cells(r, c).Value2 = qq.nodeTypedValue
Next qq
c = 0
Next pp
End With
ErrHandle:
End Sub
However, if I add a hyperlink and call the routine from there, the looping through the xml document takes about 5 seconds... Why is this happening and how can I stop it!?
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Select Case Target.Range.Address(False, False)
Case "A1"
Test
End Select
End Sub
I'm simply calling the routine from another place. I don't have any calculations on the sheet nor is there any other worksheet events. Like I say, if I run the Test
routine from my IDE it works in milliseconds...