Dim objExcelApp
Set objExceIApp=CreateObject("Excel.Application")
objExceIApp.Visible=True
objExcelApp.Workbooks.Open"D:\b1.xls"
objexcelapp.worksheets(sheet1).Cells(5,3).Value =2
objEXceIApp.ActiveWorkbooks.Save
objEXceIApp.wokebooks.close
objExcelApp.Quit
为什么excel上没数据呢,跪求大侠指教
问题补充:
Dim objExcelApp
Set objExcelApp=CreateObject("Excel.Application")
objExcelApp.Visible=True
objExcelApp.Workbooks.Open "D:\b1.xls"
objExcelApp.Worksheets("Sheet1").Cells(5,3).Value =2
objEXcelApp.Activeworkbook.Save
objEXcelApp.Workbooks.close
objExcelApp.Quit
改了以后还是不能把数据写到excel啊,求赐教,刚接手wincc项目,不是很懂啊,是不是要把excel和wincc连接起来啊,但做报表的例子上不用连接啊,
最佳答案
有多处错误 ,改正如下
Dim objExcelApp
Set objExcelApp=CreateObject("Excel.Application")
objExcelApp.Visible=True
objExcelApp.Workbooks.Open "D:\b1.xls"
objexcelapp.worksheets("sheet1").Cells(5,3).Value =2
objEXcelApp.ActiveWorkbook.Save
objEXcelApp.workbooks.close
objExcelApp.Quit
提问者对于答案的评价:
指出来了错误,但我还是想问下大神,我刚接手导师的wincc项目,我仅仅想试试在wincc中组态一个按钮通过vbs给excel写入一个值。
程序如下
Sub OnClick(Byval Item)
Dim fname
fname ="D:\Book1.xls"
Dim ObjEXcelApp
Set objExcelApp=CreateObject("Excel.Application")
objExcelApp.Visible=True
objExcelApp.Workbooks.Open fname
ObjExcelApp.Worksheets("Sheet1").Activate
objExcelApp.Worksheets("Sheet1").Cells(5,3).Value =2
objEXcelApp.ActiveWorkbook.Save
objEXcelApp.Workbooks.Close
objExcelApp.Quit
Set objExcelApp = Nothing
End Sub
为什么运行后,再打开D盘的Book1后,里面什么都没有?
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc254717.html