String Access VB-Shell字符串问题
正在尝试创建用于Access VB中的Shell命令的字符串。如果以完整形式写入字符串,则该字符串可以工作,但如果我尝试在字符串中使用变量,则即使使用变量生成的字符串正好是完整的字符串(在即时窗口中),该命令也无法工作 我怀疑在解释字符串版本的代码时出现了一些问题,但无法找出原因 下面是代码,我使用CHR(34)生成了我想在字符串中显示的引号。非常感谢您的建议-我的头发不多了 私人助理 将strFilePath设置为字符串String Access VB-Shell字符串问题,string,vb.net,shell,ms-access,String,Vb.net,Shell,Ms Access,正在尝试创建用于Access VB中的Shell命令的字符串。如果以完整形式写入字符串,则该字符串可以工作,但如果我尝试在字符串中使用变量,则即使使用变量生成的字符串正好是完整的字符串(在即时窗口中),该命令也无法工作 我怀疑在解释字符串版本的代码时出现了一些问题,但无法找出原因 下面是代码,我使用CHR(34)生成了我想在字符串中显示的引号。非常感谢您的建议-我的头发不多了 私人助理 将strFilePath设置为字符串 将strFileName设置为字符串 作为字符串的Dim strZipF
将strFileName设置为字符串
作为字符串的Dim strZipFilename
将strpdfilename设置为字符串
Dim strShellString作为字符串
将壳变暗为对象
结果很长
Set shell = CreateObject("WScript.shell")
strFilePath = "E:\Documents\Excel Spreadsheets\Roz Theremas\Access\PDFs"
strFileName = "17-03-31temp"
strZipFilename = strFilePath & "\" & strFileName & ".zip"
strZipFilename = Chr(34) & strZipFilename & Chr(34)
strPDFfilename = strFilePath & "\" & strFileName & ".pdf"
strPDFfilename = Chr(34) & strPDFfilename & Chr(34)
strShellString = Chr(34) & Chr(34) & Chr(34) & "C:\Program Files\7-Zip\7z.exe" & Chr(34) & Chr(34) & " a -tzip " & Chr(34) & strZipFilename & Chr(34) & " " & Chr(34) & strPDFfilename & Chr(34) & Chr(34)
Set shell = CreateObject("WScript.shell")
strPassword = "frog"
strFilePath = "E:\Documents\""Excel Spreadsheets""\""Roz Theremas""\Access\PDFs"
strFileName = "17-03-31temp"
strZipFilename = strFilePath & "\" & strFileName & ".zip"
strPDFfilename = strFilePath & "\" & strFileName & ".pdf"
result = shell.Run("""C:\Program Files\7-Zip\7z.exe"" a -tzip " & "-p" & strPassword & " " & strZipFilename & " " & strPDFfilename, 0, True)
'非工作shell命令
result = shell.Run("""C:\Program Files\7-Zip\7z.exe"" a -tzip ""E:\Documents\Excel Spreadsheets\Roz Theremas\Access\PDFs\17-03-31temp.zip"" ""E:\Documents\Excel Spreadsheets\Roz Theremas\Access\PDFs\17-03-31temp.pdf""", 0, False)
结果=shell.Run(strShellString,0,False)
'工作shell命令
result = shell.Run("""C:\Program Files\7-Zip\7z.exe"" a -tzip ""E:\Documents\Excel Spreadsheets\Roz Theremas\Access\PDFs\17-03-31temp.zip"" ""E:\Documents\Excel Spreadsheets\Roz Theremas\Access\PDFs\17-03-31temp.pdf""", 0, False)
'strShellString的即时窗口输出
“C:\Program Files\7-Zip\7z.exe”“a-tzip”“E:\Documents\Excel电子表格\Roz Theremas\Access\pdf\17-03-31temp.Zip”“E:\Documents\Excel电子表格\Roz Theremas\Access\pdf\17-03-31temp.pdf”“”
End Sub我的头发被保存下来了-我找到了答案!所以,对后人来说,它就在这里 我修改了strFilePath,在两个单词的文件夹名称周围加上引号,并删除了strZipFilename和strpdfilename行周围的引号。我猜壳牌公司的报价太多了 在修改它的同时,我向zip文件添加了一个密码,并在string命令的末尾将false改为true,这样它将返回一个错误代码 感谢所有花时间尝试了解我所做的事情的人 公共子临时工() 将strFilePath设置为字符串
将strFileName设置为字符串
作为字符串的Dim strZipFilename
将strpdfilename设置为字符串
将strPassword变暗为字符串
将壳变暗为对象
结果很长
Set shell = CreateObject("WScript.shell")
strFilePath = "E:\Documents\Excel Spreadsheets\Roz Theremas\Access\PDFs"
strFileName = "17-03-31temp"
strZipFilename = strFilePath & "\" & strFileName & ".zip"
strZipFilename = Chr(34) & strZipFilename & Chr(34)
strPDFfilename = strFilePath & "\" & strFileName & ".pdf"
strPDFfilename = Chr(34) & strPDFfilename & Chr(34)
strShellString = Chr(34) & Chr(34) & Chr(34) & "C:\Program Files\7-Zip\7z.exe" & Chr(34) & Chr(34) & " a -tzip " & Chr(34) & strZipFilename & Chr(34) & " " & Chr(34) & strPDFfilename & Chr(34) & Chr(34)
Set shell = CreateObject("WScript.shell")
strPassword = "frog"
strFilePath = "E:\Documents\""Excel Spreadsheets""\""Roz Theremas""\Access\PDFs"
strFileName = "17-03-31temp"
strZipFilename = strFilePath & "\" & strFileName & ".zip"
strPDFfilename = strFilePath & "\" & strFileName & ".pdf"
result = shell.Run("""C:\Program Files\7-Zip\7z.exe"" a -tzip " & "-p" & strPassword & " " & strZipFilename & " " & strPDFfilename, 0, True)