Short Background
I've got an application that I built in Excel, and I'm attempting to add functionality where Excel acts as a controller and runs different VBScript files (I know this sounds like an odd case, but bear with me). To test the concept, I wrote a short VBScript that simply Echos the path to the folder that the script is in.
VBScript (run-from-excel.vbs)
Set fso = CreateObject("Scripting.FileSystemObject")
scriptPath = fso.GetAbsolutePathName(".")
WScript.Echo(scriptPath)
When run with cscript run-from-excel.vbs from a console in the proper directory, the output is: C:\Users\cmfonvi\dev\vbscript, which is as expected.
Now, for the Excel integration. I wrote a simple Sub that runs a VBScript file through WScript on the console.
VBA - Excel
Sub runVBScript(filePath As String)
Shell "wscript " & filePath, vbNormalFocus
End Sub
I now run this Sub, with the command
runVBScript (ActiveWorkbook.Path & "\run-from-excel.vbs")
(the workbook and VBScript are currently in the same directory, so this works). However, the output is not as I expected. The window it opens outputs C:\Users\cmfonvi\Documents, which means that somehow the wscript process running the VBScript is initialized in the %userprofile%\Documents directory.
My question is two-fold:
- Why is this the case?
- How can I make the console initialize in the proper directory (say, for example, in
%userprofile%\Desktop)?