用双引号括起完整的文件路径

Ana*_*ach 1 ftp excel vba excel-vba

我有一个文件,我需要使用VBA FTP,我已经想到它的大部分,除了我需要"在文件名中插入但不能做的最后一个.

csvPath = "C:\Users\10613527\Desktop\test\"
sWorkingDirectory = csvPath
sFileToSend = "Price_Change_10-08-15 20-35-49.csv"

iFreeFile = FreeFile
Open sWorkingDirectory & FTP_BATCH_FILE_NAME For Output As #iFreeFile
Print #iFreeFile, "open " & FTP_ADDRESS
Print #iFreeFile, FTP_USERID
Print #iFreeFile, FTP_PASSWORD
Print #iFreeFile, "ASCII"
Print #iFreeFile, "put " & sWorkingDirectory & sFileToSend
Print #iFreeFile, "dir"
Close #iFreeFile

'Shell command the FTP file to the server
Shell "ftp -i -w:20480 -s:" & sWorkingDirectory & FTP_BATCH_FILE_NAME
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,我得到了找不到文件的错误.

在此输入图像描述

原因是文件路径和名称不在"",例如此代码正在编写另一个脚本文件并执行该文件.

所以它需要

open ftp path
username
password 
ASCII
put "C:\Users\10613527\Desktop\test\Price_Change_10-08-15 20-35-49.csv"
dir
Run Code Online (Sandbox Code Playgroud)

并不是

open ftp path
username
password 
ASCII
put C:\Users\10613527\Desktop\test\Price_Change_10-08-15 20-35-49.csv
dir
Run Code Online (Sandbox Code Playgroud)

注意" "PUT语句中,我不知道如何将它们放在那里.

Vin*_*t G 5

用于在vb字符串中""转义".

所以

Print #iFreeFile, "put """ & sWorkingDirectory & sFileToSend & """"
Run Code Online (Sandbox Code Playgroud)