Daily Report Script Not Working

Dear All

Hi All Currently I have a project with the Aveva Plant Scada 2020 R2 (v8.30) program where the customer has a request regarding the Daily Report in Excel format and Trigger at 00:00 for every day, I have tried to make a cicode script with trigger every hour for more details you can see Cicode script below:

//---------------------------------------------------------------- ------

// To trigger save data per hour

//---------------------------------------------------------------- ------

FUNCTION trigger();

//INT A

Minutes = TimeMin(TimeCurrent());

det = TimeSec(TimeCurrent());

IF Minute = 0 AND sec = 0 AND A = 0 THEN

A=1;

write()

END

IF det >= 5 THEN A=0 END

END

//------------------------------------------------------
//            To trigger save daily
//------------------------------------------------------

FUNCTION write()

ExcelDate = Date (3) ;

NewFileName = ExcelDate ;

FileCopy("C:\Report_Harian_MS2.xlsx","C:\REPORT\Harian\Report_Shift_"+NewFileName+".xlsx",0);

Exec ("C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.exe C:\REPORT\Harian\Report_Shift_"+NewFileName+".xlsx",6);

DDEWrite("Excel","C:\REPORT\Harian\Report_Shift_"+NewFileName+".xlsx","R6C3",Date (2));

DDEWrite("Excel","C:\REPORT\Harian\Report_Shift_"+NewFileName+".xlsx","R11C4",2000);


DDEExec("EXCEL.EXE","[Close(1)]");
DDEExec("EXCEL.EXE","[Quit]");

END

Local Tags

A = INT

NewFileName = STRING

Menit = INT

det = INT

From the results that I have done where the script does not automatically create an excel file in the folder, but if I do it manually (Via Button) the file is stored in the folder that has been created, I will also inform you that I have entered the cicode function ( trigger() )in the cicode object in the header menu that should be able to run automatically.

can you help me to solve this problem.

Thank's