vba- parse xml that i go from webserver and write it to excel takeing to much tim -
i trying write excel more 50000 rows etch row have 11 cells it's taking me more them 18 minutes so. can tell me am doing wrong?? seeing of time spending on writing values variant , not actual writing excel
thanks itay
public sub updateresultssheet() dim ws worksheet: set ws = activesheet dim newbook excel.workbook: set newbook = activeworkbook dim suppdistbranchid string dim suppprodid string dim reportingdate string dim query string dim nodecell ixmldomnode dim rowcount integer dim cellcount integer dim rowrange range dim cellrange 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 new xmlhttp req.open "get", query, false req.send dim resp new domdocument resp.loadxml req.responsetext dim inventoyhistory ixmldomnode application.visible = true application.screenupdating = false application.displaystatusbar = false application.enableevents = false ws.displaypagebreaks = false dim origcalc excel.xlcalculation origcalc = application.calculation application.calculation = xlcalculationmanual const blocksize long = 1000 dim values() variant redim values(blocksize, 11) dim idx long idx = 1 dim rownumber long rownumber = 2 dim celinx integer resp.getelementsbytagname ("dailyinventoryhistory") celinx = 0 dim starttime double starttime = timer each inventoyhistory in resp.getelementsbytagname("dailyinventoryhistory") celinx = 0 each nodecell in inventoyhistory.childnodes values(idx, celinx) = nodecell.nodetypedvalue celinx = celinx + 1 next nodecell idx = idx + 1 if idx = blocksize - 1 ws .range(.cells(rownumber, 1), .cells(rownumber + blocksize - 1, 11)).value = values end idx = 1 redim values(blocksize, 11) rownumber = rownumber + blocksize end if next ' write last block ws .range(.cells(rownumber, 1), .cells(rownumber + blocksize - 1, 11)).value = values end 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>
Comments
Post a Comment