• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Execute Shell command (File Name having a space)

inddon

Member
Hello There,

I have the below code which runs a sheel command to open a pdf file. The application does open but the file does not open. If I remove the space from the file name the pdf file opens. Could you please help in providing a generic VBA code to open a file. Which can handle both a space and a no space in the filename?

Code:
Sub tt()
  Dim AdobeExecutable As String, AdobeFile As String, StartAdobe
  AdobeExecutable = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
  AdobeFile = "E:\ABC dd.pdf"
   
  StartAdobe = Shell("" & AdobeExecutable & " " & AdobeFile & "", 0)
End Sub
Thank you & regards,
Don
 

shrivallabha

Excel Ninja
Hello There,

I have the below code which runs a sheel command to open a pdf file. The application does open but the file does not open. If I remove the space from the file name the pdf file opens. Could you please help in providing a generic VBA code to open a file. Which can handle both a space and a no space in the filename?

Code:
Sub tt()
  Dim AdobeExecutable As String, AdobeFile As String, StartAdobe
  AdobeExecutable = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
  AdobeFile = "E:\ABC dd.pdf"
  
  StartAdobe = Shell("" & AdobeExecutable & " " & AdobeFile & "", 0)
End Sub
Thank you & regards,
Don
Add pair of quotes to deal with it like below.

Code:
StartAdobe = Shell("" & AdobeExecutable & " """ & AdobeFile & """", 0)
 
Top