Skip to content Skip to sidebar Skip to footer

Javascript To Call A Vba Routine With Parameters

I need to pass arguments to a Excel VBA code from JavaScript of HTA. I can successfully call VBA function, but unable to pass string arguments correctly. JavaScript function can

Solution 1:

I'm thinking you want:

objWb.Application.Run('testing_excel_web.xls!subTest("' + strName + '")');

This way, the value of the variable strName is concatenated to the command you are attempting to run.

I know nothing about this calling of a VBA function, so I'm not sure if you need the " around the strName like I provided or not.

In addition, to be safe, in case your strName value contains ", you should use this:

objWb.Application.Run('testing_excel_web.xls!subTest("' + strName.replace(/"/g, "\"") + '")');

Hopefully with this, the value of strName could be

The word "testing" here
or
"Here's a quote"

and it will still work.

The point is that if the string contains ", the Javascript would/could fail. If it would absolutely never contain ", then forget about it. But I think it's needed since any " in the value of strName will break the passing of it as a parameter.

Post a Comment for "Javascript To Call A Vba Routine With Parameters"