1
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. 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. What am I doing wrong?

3
  • I think you are missing the quotes sign in the string. Shouldn't the Immediate window output the string without the " character ? Commented Mar 15, 2016 at 22:01
  • @Santosh Without the quotes around %ProgramFiles(x86)%\TextPad 5\TextPad.exe, the command doesn't run in a shell window. Commented Mar 15, 2016 at 22:07
  • It might be the percentage sign that needs escaping. If you remove them and give entire full path, does Excel VBA Shell work? Commented Mar 16, 2016 at 1:06

1 Answer 1

2

Use Environ function to get Special Folders

pathSpecial = Environ("ProgramFiles(x86)")
shellCommand = """" & pathSpecial  & "\TextPad 5\TextPad.exe"" -r -q -u """ & filePath & agingsEntry & """ -u """ & filePath & invenEntry & """"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.