vbaparsingxml,我从web服务器,并写入excel采取很多tim

我想写一个更多的50000行的蚀刻行有11个单元格,这使我更多的18分钟这样做。 有人可以告诉我,我在做什么错? 我看到,大部分时间都花在写入价值变体上,而不是写入Excel中

谢谢itay

public Sub updateResultsSheet() Dim ws As Worksheet: Set ws = ActiveSheet Dim NewBook As Excel.Workbook: Set NewBook = ActiveWorkbook Dim suppDistBranchId As String Dim suppProdId As String Dim reportingDate As String Dim query As String Dim nodeCell As IXMLDOMNode Dim rowCount As Integer Dim cellCount As Integer Dim rowRange As Range Dim cellRange As Range rowCount = 1 query = "http://******:8080/RS_Excel_API/dailyInvHist/get/1?" reportingDate = Trim(Range("Parameters!F" + CStr(2)).Value & vbNullString) query = query + "reportingDate=" query = query + reportingDate Dim Req As New XMLHTTP Req.Open "GET", query, False Req.send Dim Resp As New DOMDocument Resp.LoadXML Req.responseText Dim InventoyHistory As IXMLDOMNode Application.Visible = True Application.ScreenUpdating = False Application.DisplayStatusBar = False Application.EnableEvents = False ws.DisplayPageBreaks = False Dim OrigCalc As Excel.XlCalculation OrigCalc = Application.Calculation Application.Calculation = xlCalculationManual Const BlockSize As Long = 1000 Dim Values() As Variant ReDim Values(BlockSize, 11) Dim idx As Long idx = 1 Dim RowNumber As Long RowNumber = 2 Dim celInx As Integer Resp.getElementsByTagName ("DailyInventoryHistory") celInx = 0 Dim StartTime As Double StartTime = Timer For Each InventoyHistory In Resp.getElementsByTagName("DailyInventoryHistory") celInx = 0 For Each nodeCell In InventoyHistory.ChildNodes Values(idx, celInx) = nodeCell.nodeTypedValue celInx = celInx + 1 Next nodeCell idx = idx + 1 If idx = BlockSize - 1 Then With ws .Range(.Cells(RowNumber, 1), .Cells(RowNumber + BlockSize - 1, 11)).Value = Values End With idx = 1 ReDim Values(BlockSize, 11) RowNumber = RowNumber + BlockSize End If Next ' write last block With ws .Range(.Cells(RowNumber, 1), .Cells(RowNumber + BlockSize - 1, 11)).Value = Values End With Application.ScreenUpdating = True Application.Calculation = OrigCalc Application.Visible = True Application.DisplayStatusBar = True Application.EnableEvents = True ws.DisplayPageBreaks = True MsgBox Format(Timer - StartTime, "0000.00") & " seconds" End Sub XMl exmple: <xML_DailyInventoryHistories> <DailyInventoryHistory> <calcOp>0</calcOp> <calcOq>1</calcOq> <dmiDistBranchId>0</dmiDistBranchId> <netQtyAvailable>0</netQtyAvailable> <qtyAvailable>0</qtyAvailable> <qtyCommittedToSale>0</qtyCommittedToSale> <qtyOnHand>0</qtyOnHand> <qtySold>0</qtySold> <supplierNetPrice>0.599</supplierNetPrice> <usedOp>0</usedOp> <usedOq>1</usedOq> </DailyInventoryHistory> <DailyInventoryHistory> <calcOp>0</calcOp> <calcOq>1</calcOq> <dmiDistBranchId>0</dmiDistBranchId> <netQtyAvailable>0</netQtyAvailable> <qtyAvailable>0</qtyAvailable> <qtyCommittedToSale>0</qtyCommittedToSale> <qtyOnHand>0</qtyOnHand> <qtySold>0</qtySold> <supplierNetPrice>0.599</supplierNetPrice> <usedOp>0</usedOp> <usedOq>1</usedOq> </DailyInventoryHistory> </xML_DailyInventoryHistories>