0

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 :(

thangvc91
  • 323
  • 2
  • 10
  • you are possibly asking the wrong question ... maybe the question to ask is `how to obtain GetLocale in VBA?` – jsotola Dec 26 '21 at 00:17
  • have a read of this https://stackoverflow.com/questions/42122216/vbscript-getlocale-setlocale-other-uses - it shows how to run vbscript getLocale and assign to a variable – Ian Kenney Dec 26 '21 at 00:18
  • Does this answer your question? [Capture output value from a shell command in VBA?](https://stackoverflow.com/questions/2784367/capture-output-value-from-a-shell-command-in-vba) –  Dec 26 '21 at 00:19

1 Answers1

0

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