I'm attempting to call a powershell script in an VBA macro in Excel, but run into an error due to spaces in the file path. I've seen similar questions asked where people suggest surrounding the path with double quotes, Chr(34), etc., but that hasn't worked.
Here is my code:
Path = ActiveWorkbook.Path
shell_path = Path & "\upload.ps1"
shell_script = "POWERSHELL.exe -noexit """ & shell_path & """"
Shell (shell_script)
Variable values:
- Path = "Y:\File Path"
- shell_path = "Y:\File Path\upload.ps1"
- shell_script = "POWERSHELL.exe -noexit "Y:\File Path\upload.ps1""
Upon running Shell(shell_script), I get the following error message in powershell:
Y:\File: The term 'Y:\File' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Y:\File Path\upload.ps1
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Y:\File:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
It seems like the Shell command is ignoring the extra set of quotes around the file path in the shell_script string. Also, if I move the file to a path that doesn't have spaces, everything runs fine (but that isn't a long term solution). Any ideas on what to do?