问题是:如何刷新/阻止Excel膨胀我的RAM。
我有一堆html字符串存储在一个单独的Sheet中,它指向不同的xml web数据,我创建了一个循环:
我正在考虑在数组中处理xml而不是将它们导入到工作表中,因为我还没有找到另一种解决方法,但我担心这超出了我的技能水平。非常感谢所有帮助。
答案 0 :(得分:0)
我得到了一个解决方案并且正在运行。感谢@Blackhawk指出我正确的方向。 它将xml加载到de MSXML DOM中,并基于GetElementsByTagName迭代NodeList。 然后它使用几个字符串函数和循环将我之后的信息提取到数组中。
我很满意它的工作,但请随时指出它可以做得更好!
Sub IterateThroughNodelistXML()
Application.ScreenUpdating = False
Dim MyArray(1 To "some upper bound", 1 To 3)
Dim xmldoc As MSXML2.DOMDocument
Dim xmlNodeList As MSXML2.IXMLDOMNodeList
Dim xmlNode As MSXML2.IXMLDOMNode
Dim web_addresses, XML_Output As Worksheet
Dim str, strHttp, strValue_1, strValue_2 As String
Dim intPosition_1, intPosition_2 As Integer
Dim l, s As Integer
Dim i, bAscii As Byte
Dim c As Long
Dim dDate As Date
Set XML_Output = Sheets(1)
Set web_addresses = Sheets(2)
Set xmldoc = New MSXML2.DOMDocument
xmldoc.async = False
For l = 1 To web_addresses.Range("a1").CurrentRegion.Rows.Count
strHttp = web_addresses.Cells(l, 1).value
xmldoc.Load ("http://www.some_web_page" & strHttp)
Set xmlNodeList = xmldoc.getElementsByTagName("something")
For s = 1 To xmlNodeList.Length
str = xmlNodeList.Item(s).nodeTypedValue
intPosition_1 = InStrRev(str, "some search string", -1, vbBinaryCompare) - "some constant"
strValue_1 = Mid(str, intPosition_1, "some constant")
i = 9
bAscii = 0
While bAscii < 48 Or bAscii > 57
intPosition_2 = InStr(1, str, "some other search string", vbBinaryCompare) - i
strValue_2 = Mid(str, intPosition_2, i)
bAscii = AscW(strValue_2)
i = i - 1
Wend
c = c + 1
dDate = Date
MyArray(c, 1) = strValue_1
MyArray(c, 2) = strValue_2
MyArray(c, 3) = dDate
Next s
Next l
XML_Output.Range("a4").Resize(UBound(MyArray, 1), UBound(MyArray, 2)).value = MyArray
Application.ScreenUpdating = True
End Sub