简体   繁体   English

Excel VBA Shell命令在文件路径中带有空格

[英]Excel VBA Shell command with spaces in file path

Public Sub openEntryFiles()
Dim filePath, shellCommand, agingsEntry, invenEntry As String
filePath = Range("CustomerPath").Value2 & "\files\"
agingsEntry = "agings\entry_EP.bat"
invenEntry = "inven\entry_EP.bat"

shellCommand = """%ProgramFiles(x86)%\TextPad 5\TextPad.exe"" -r -q -u """ & filePath & agingsEntry & """ -u """ & filePath & invenEntry & """"
Debug.Print shellCommand
Shell shellCommand, 0
End Sub

I am trying to write a subroutine that will run a shell command with spaces in the file path. 我正在尝试编写一个子例程,该子例程将在文件路径中运行带空格的shell命令。 I have done lots of research about using multiple quotes, but I still get a file not found error whenever I run the code. 我已经对使用多引号进行了很多研究,但是每当我运行代码时,仍然会出现文件未找到错误。 The debug print that is outputted to the Immediate window reads: 输出到立即窗口的调试打印内容如下:

"%ProgramFiles(x86)%\TextPad 5\TextPad.exe" -r -q -u "\\ablsgaat002\aclwin\Clients\*****\files\agings\entry_EP.bat" -u "\\ablsgaat002\aclwin\Clients\*****\files\inven\entry_EP.bat"

Copying that string into a shell window works great, however, running it from the Shell command in VBA doesn't work. 将该字符串复制到Shell窗口中效果很好,但是,无法在VBA中从Shell命令运行它。 What am I doing wrong? 我究竟做错了什么?

Use Environ function to get Special Folders 使用Environ功能获取特殊文件夹

pathSpecial = Environ("ProgramFiles(x86)")
shellCommand = """" & pathSpecial  & "\TextPad 5\TextPad.exe"" -r -q -u """ & filePath & agingsEntry & """ -u """ & filePath & invenEntry & """"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM