-1

I am currently working on a code where in there is an existing sample.vbs which is being executed in a html application (.hta). It works perfectly in there.

Now I need to transfer the GUI into VBA and I am calling the exact sample.vbs exactly the same how it being executed in the .hta (html application)

The problem is that I am having an error when executing the link: It says Runtime error 450 "wrong number of argument or invalid property assignment"

Dim oShell, returnCode
Set oShell = CreateObject("WScript.Shell")
Set returnCode = oShell.exec("sample.vbs -U " & param1 & " -P " & param2 & " -E " & param3  & ".", , True)

What seems to be the problem here?

Thanks in advance!

5
  • 1
    If you are going to use VBA anyway why not transfer the code to VBA? After all VBScript and VBA are from the same family of programming languages. Commented Dec 11, 2023 at 8:02
  • Is there a reason you need to use the VBS file? Why add that extra layer of possible problems? Would it be to maybe bypass a filter of some sort? Commented Dec 11, 2023 at 8:19
  • the code in the .vbs file is too complex and a lot to convert it in vba.. so i would like to stay in the same and just call it in vba.. Commented Dec 11, 2023 at 8:42
  • Is it actually running the vbs script and that is what is giving you the error, or is it because there is no path to the vbs file and it's shell that gives you the error? Commented Dec 11, 2023 at 8:54
  • If you transfer the VBScript to VBA then it will still work when MS disables VBScript. Commented Dec 11, 2023 at 9:35

1 Answer 1

-1

It depends on what the respective VBScript does. I mean, do you need to press UAC button to allow it running? In such a case you must adapt the script to call itself in a way to run "As Administrator".

If not, I always use the next way of running a VBScript. Even one written on the fly in the same procedure:

 shell "cmd.exe /c """ & strVBSPath & """", 0 '0 - open cmd in hidden window

Where strVBSPath is, of course, the script full name...

Or run it As Administrator in the next way:

Dim oShell As Object: Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "cmd.exe", "/k cscript //nologo c:temp\run.vbs", , "runas", 1

'or using `Cscript.exe`:

oShell.ShellExecute "cscript.exe", "//nologo c:temp\run.vbs", , "runas", 1

Now I can see that you try calling the script with parameters. Please, try the next way (used by me and working):

Dim cmdStr as String
cmdStr = "cscript """ & scriptPath & """ """ & strParam & """"

'or, for two parameters:

cmdStr = "cscript """ & scriptPath & """ """ & strParam & """ """ & strParam2 & """"
Shell cmdStr, 0

Of course, strParam and strParam2 are the string parameters...

Sign up to request clarification or add additional context in comments.

3 Comments

@Toshi Didn't you find some time to test the above suggestions? If tested, didn't they do what you need?
I tried both, The error eliminated but the functionality from the vbs file seems not triggered.
@Toshi OK. Please, add the script path in Excel Trusted Locations: Options -> Trust Center -> Trust Center Settings... -> Trusted Locations where press Add New location.... A Browse window is open, select the respective folder and press OK. Press OK in Trusted Locations, too. If you need to spread your code to many users, I can supply a piece of code able to automatically add it to Trusted Locations. It is a little more complex...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.