1

I wish to use thing string useing Shell() function to automate an upload of an excel file to an ftp server whenever a save occurs:

strShell = "C:\Program Files\WinSCP\WinSCP.exe /console /command " & Chr(34) & "option batch on" & Chr(34) & " " & Chr(34) & "open user:pass@localhost" & Chr(34) & " " & Chr(34) "put " ThisWorkbook.Path & "/" & ThisWorkbook.Name & "/home/User/Directory" & Chr(34) & " " & Chr(34) "exit" & Chr(34)

For some reason I get syntax error for this string. My knowledge in VBA isn't wide but I going over MSDNfor the last couple of hours didn't seem to help at all.

2
  • 2
    Aren't you missing a space before /home/User/Directory? Commented Oct 22, 2014 at 13:34
  • @jbarker2160, I am, thanks. But sadly this typo doesn't solve the syntax error. Commented Oct 22, 2014 at 13:35

2 Answers 2

2

I suspect that you need more quotes for file paths containing spaces. Something like strShell = "'C:\Program Files\WinSCP\WinSCP.exe' /console /command " & Chr(34) &....

you also forgot some "&" like on the 3dr line:
Chr(34) & "put " & ThisWorkbook.Path &
Again on that line, you might need to surround filenames with quotes !

Your best help would be to include a Debug.Print strShell and watch the result in the VBE Immediate Window (^G)

Sign up to request clarification or add additional context in comments.

1 Comment

woha, I forgot more than one &
0

According to the documentation for WinSCP, you need to add the double quotes around your commands. For Example: WinSCP.exe /command "option batch abort"

So in VBA that would be: "WinSCP.exe /command ""option batch abort"""

1 Comment

AFAIK Chr(34) is "

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.