Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join us at the Cloud Data and Analytics Tour! REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
Marius_
Contributor II
Contributor II

Function execute in load script: Error message

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

2 Replies
marcus_sommer
MVP & Luminary
MVP & Luminary

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

Brett_Bleess
Support (Former)
Support (Former)

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...

https://help.qlik.com/en-US/qlikview/April2020/Subsystems/Client/Content/QV_QlikView/VBFunctionCalls...

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.