rt
最佳答案
C脚本:
void Excel()
{
__object* pExcel = NULL;
__object* pWorkbooks = NULL;
__object* pActiveWorkbook = NULL;
pExcel = __object_create("Excel.Application.8"); //8 for Excel 97
// pExcel = __object_create("Excel.Application.9"); // 9 for Excel 2k
// pExcel = __object_create("Excel.Application.10"); //10 for Excel XP
// pExcel = __object_create("Excel.Application.11"); //11 for Excel 2k3
if(pExcel) {
pExcel->Visible = 1;
pWorkbooks = pExcel->Workbooks;
pWorkbooks ->Open ("F:\\WinCCProjects\\Excel_TST.xls");
pExcel->Run("TestMacro");
pActiveWorkbook = pExcel->ActiveWorkbook;
pActiveWorkbook->Save();
__object_delete(pActiveWorkbook);
pWorkbooks->Close();
__object_delete(pWorkbooks);
pExcel->Quit();
__object_delete(pExcel);
}
}
VBS脚本:
Dim xExcel,xWorkbooks,xActiveWorkbook
Set xExcel = CreateObject("Excel.Application")
if xExcel then
xExcel.Visible = True
Set xWorkbooks = xExcel.Workbooks.Open("F:\WinCCProjects\Excel_TST.xls")
xExcel.Run "Sheet1.TestFunc"
xActiveWorkbook = xExcel.ActiveWorkbook
xActiveWorkbook.Save
set xActiveWorkbook = Nothing
xWorkbooks.Close
set xWorkbooks = Nothing
xExcel.Quit
set xExcel = Nothing
end_if
提问者对于答案的评价:
大家都答得很好,可没办法,只能挑一个,那我就随便选一个吧。
谢谢大家!!!中秋快乐!!
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc276272.html