-- 作者:deni977
-- 发布时间:2014/4/1 1:02:23
-- 交易结果记录excel
自定义函数VBA部份:
Function Wxls(Formula,V1,v2,v3,v4,v5,v6,v7,v8,v9,v10) Wxls=0 dim objExcel,objWorkbook on error resume next Set objExcel = getObject("Excel.Application") if err.number<>0 then Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("d:\\test\\Test.xlsx") \'打开指定文件 end if objExcel.Visible = True vbRow=objExcel.sheets(1).UsedRange.Rows.Count+1 objExcel.sheets(1).Cells(vbRow,1).Value = (date) objExcel.sheets(1).Cells(vbRow,2).Value = V1 objExcel.sheets(1).Cells(vbRow,3).Value = V2 objExcel.sheets(1).Cells(vbRow,4).Value = V3 objExcel.sheets(1).Cells(vbRow,5).Value = V4 objExcel.sheets(1).Cells(vbRow,6).Value = V5 objExcel.sheets(1).Cells(vbRow,7).Value = V6 objExcel.sheets(1).Cells(vbRow,8).Value = V7 objExcel.sheets(1).Cells(vbRow,9).Value = V8 objExcel.sheets(1).Cells(vbRow,10).Value = V9 objExcel.sheets(1).Cells(vbRow,11).Value = V10 objExcel.Application.Displayalerts = false objExcel.application.Save objExcel.application.quit End Function
在一个后台PEL中写入如下语句:
Wr:=Wxls(Profit11,Profit12,Profit13,Profit14,Profit15,Profit16,Profit17,Profit18,Profit19,Profit20);//写入Excel表格
程序没有执行写入excel的动作。不知道哪里偶问题?
但是,还是这一句Wr:=Wxls(Profit11,Profit12,Profit13,Profit14,Profit15,Profit16,Profit17,Profit18,Profit19,Profit20);执行在图表下,就有写入excel,请问哪里写错了?
|
-- 作者:deni977
-- 发布时间:2014/4/2 21:40:30
--
确实很郁闷,我用的是3.11版本,代码如下:
GLOBALVARIABLE:Flag:=1;
Latime:=DYNAINFO(207);
if (( Latime=213301 )&& barstatus=2 && Flag=ref(Flag,1)) then begin Profit11:=2; Profit12:=2; Profit13:=3; Profit14:=4; Profit15:=5; Profit16:=6; Profit17:=7; Profit18:=8; Profit19:=9; Profit20:=10; Profit21:=11; Profit22:=12; Profit23:=13; Wr:=Wxls(Profit11,Profit12,Profit13,Profit14,Profit15,Profit16,Profit17,Profit18,Profit19,Profit20);//写入Excel表格 // debugout(\'latime=%.0f\',latime); Tmp:=not(Flag); Flag:=Tmp; end
在图表下确实写入excel表格了,而且存盘退出。
同样这段代码,运行在后台,1秒周期或者1分周期,都是一样的结果:没有操作excel表格
此主题相关图片如下:11.jpg

|
-- 作者:deni977
-- 发布时间:2014/4/3 0:22:19
--
在VBA代码段,增加信息输出的 “msgbox v10”,如下,后台调用时,是有输出信息框的,证明程序已经运行到信息提示行这里:
Function Wxls(Formula,V1,v2,v3,v4,v5,v6,v7,v8,v9,v10) Wxls=0 dim objExcel,objWorkbook on error resume next Set objExcel = getObject("Excel.Application") if err.number<>0 then Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("d:\\test\\Test.xlsx") \'打开指定文件 end if objExcel.Visible = True vbRow=objExcel.sheets(1).UsedRange.Rows.Count+1 objExcel.sheets(1).Cells(vbRow,1).Value = (date) objExcel.sheets(1).Cells(vbRow,2).Value = V1 objExcel.sheets(1).Cells(vbRow,3).Value = V2 objExcel.sheets(1).Cells(vbRow,4).Value = V3 objExcel.sheets(1).Cells(vbRow,5).Value = V4 objExcel.sheets(1).Cells(vbRow,6).Value = V5 objExcel.sheets(1).Cells(vbRow,7).Value = V6 objExcel.sheets(1).Cells(vbRow,8).Value = V7 objExcel.sheets(1).Cells(vbRow,9).Value = V8 objExcel.sheets(1).Cells(vbRow,10).Value = V9 objExcel.sheets(1).Cells(vbRow,11).Value = V10
msgbox v10 objExcel.Application.Displayalerts = false objExcel.application.Save objExcel.application.quit End Function
问题还是纠结在:没有打开excel表格和将数据写入excel,但是测试仍然发现,在图表下正常,盼盼高手指导
|