Quaker
Quaker

Reputation: 1553

Visual Basic string syntax error while trying to automate WinSCP

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.

Upvotes: 1

Views: 256

Answers (2)

Mr. Mascaro
Mr. Mascaro

Reputation: 2733

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"""

Upvotes: 0

iDevlop
iDevlop

Reputation: 25272

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)

Upvotes: 2

Related Questions