以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://weistock.com/bbs/index.asp) -- 高级功能研发区 (http://weistock.com/bbs/list.asp?boardid=5) ---- [分享]VBA写螺纹历史数据到Excel表源代码 (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=169006) |
-- 作者:lizhi -- 发布时间:2019/3/26 22:00:02 -- [分享]VBA写螺纹历史数据到Excel表源代码 Sub WriteDataToExcel() Dim Grid,objExcel,History,i,StarTimer StarTimer = Timer \'以指定代码和周期激活或者打开一个指定的框架 Call Application.ActivateFrameWithCode("Technic","RB00","SQ",5) Set Grid = Technic.GetGridByName("Main")\'获取主图窗格 Set History = grid.GetHistoryData() \'获取主图窗格上的历史数据 \'创建EXCEL对象 Set objExcel = CreateObject("Excel.Application") With objExcel .Visible = True .Workbooks.Add .Activeworkbook.sheets("sheet1").Range("A1:G1") = _ Array("日期","开盘","最高","最低","收盘","成交量","持仓量") End With \'写数据到数组及Excel表中 Dim DataCount DataCount = History.Count Dim arr() ReDim arr(DataCount,6) For i = 0 To DataCount With History arr(i,0) = .Date(i) arr(i,1) = .Open(i) arr(i,2) = .High(i) arr(i,3) = .Low(i) arr(i,4) = .Close(i) arr(i,5) = .Volume(i) arr(i,6) = .OpenInt(i) End With Next objExcel.Range("A2:G"&DataCount+1).value = arr \'释放对象变量内存 Set Grid = Nothing Set History = Nothing Set objExcel = Nothing MsgBox "程序运行的时间="&Timer - StarTimer&"秒。" End Sub |
-- 作者:ak47ok -- 发布时间:2020/4/12 9:17:19 -- 每次回帖、谢谢!辛苦了。 |