Home > Software design >  How to pass the result of VBS to VBA as the variable
How to pass the result of VBS to VBA as the variable

Time:12-26

I would like to pass the result after run my vbs file to the VBA as the variable , however i don't know how to do that, could you please assist on this ?

my vbs code:

wscript.echo GetLocale 

'i want to pass this output (2033) and it will be assign as myvbsvar in VBA.

in VBA, i will compare it with the en-us , if this ~= 1057 -> will call another VBS script to change it into en-gb. I'm stucking in the step pass VBS to VBA :(

CodePudding user response:

You can run the script from VBA using cscript.exe and read the output from it. See Capture output value from a shell command in VBA.

If you are using Windows then this should work:

Dim MyOutput As String
MyOutput = CreateObject("WScript.Shell") _
        .Exec("C:\Windows\System32\cmd.exe /c C:\Windows\System32\cscript.exe /NOLOGO ""C:\YourScript.vbs""") _
        .StdOut _
        .ReadAll
Debug.Print MyOutput

If you want to use the 64-bit version of cscript.exe or cmd.exe, then use these paths instead:

C:\Windows\SysWOW64\cmd.exe
C:\Windows\SysWOW64\cscript.exe
  • Related