Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am trying to run a VBA macro in my script like this: (See below)
Script:
Trace #<< Text >>#;
EXECUTE CMD.EXE /c del "File.xlsx"; //Remove a temp file in office
Let vExecute = 'ExecuteExl_an()'; //Call excel
But I receive the following error even BEFORE the "Trace" script command is executed:
Script line error:
SUB
And just after the EXECUTE line the following error:
Script line error:
End Sub
I am not sure why a SUB error will occur at this point.
The macro:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Let vExecute = 'ExecuteExl_an()';
The VBA code is executed via a Function:
Function ExecuteExl_an()
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open(Path)
objWorkbook.Application.Run "Macro"
Set xlBook = Nothing
Set xlApp = Nothing
End Function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
It's not quite clear for me where do you want to do what but I think it's not possible in this way. Your error-message comes probably through the parser which detects invalid code/syntax, like the missing function return-value or that you put the function within the script and not within the macro-editor.
Beside this you couldn't call an ActiveX statement like "CreateObject" within the script-run because the for this required features/libraries aren't available in the script else only if the datamodel is built and an UI for the application exists.
What you could instead do is to call a batch-file per EXECUTE which does all the wanted work. Here an example what is meant: Run-Excel-from-QMC
- Marcus
The following Help link should provide further information along the lines Marcus was discussing along with an example. If you are just trying to detele a Temp file though, why not simply make a call to system Delete function via Cmd.exe /c Delete filename...
Regards,
Brett