|
以下代码可以在金字塔软件执行,该代码来源和整理自网络;
- ub 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
复制代码
|
|