从Access VBA调用Zint

从Access VBA调用Zint,vba,ms-access,cmd,barcode,Vba,Ms Access,Cmd,Barcode,我将在我的访问程序中使用ZINT作为条形码生成器。 我想在Access VBA中使用SHELL命令调用它。我的问题是,我无法从命令提示符调用ZINT。 这是我的密码 Private Sub cmdTest_Click() Dim strToPrint, strInfoBarcode As String strInfoBarcode = "Batch #699" strToPrint = "%ProgramFiles%\zint\zint.exe -o c:\path

我将在我的访问程序中使用ZINT作为条形码生成器。 我想在Access VBA中使用SHELL命令调用它。我的问题是,我无法从命令提示符调用ZINT。 这是我的密码

Private Sub cmdTest_Click()
    Dim strToPrint, strInfoBarcode As String

    strInfoBarcode = "Batch #699"

    strToPrint = "%ProgramFiles%\zint\zint.exe  -o c:\path\699.png -b 58 --vers=10 -d " & strInfoBarcode
    Call Shell("cmd.exe /S /K" & strToPrint, vbMinimizedNoFocus)
End Sub
当我运行上述代码时,会显示错误

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

有人能告诉我们从Access VBA调用ZINT程序的正确方法吗?

您的
程序文件中是否缺少空格?猜测这只是一个输入错误,但您应该在任何带有空格的路径周围加引号

Private Sub cmdTest_Click()
    Dim strToPrint, strInfoBarcode As String

    strInfoBarcode = "Batch #699"

    strToPrint = """%ProgramFiles%\zint\zint.exe""  -o c:\path\699.png -b 58 --vers=10 -d """ & strInfoBarcode & """"
    Call Shell("cmd.exe /S /K " & strToPrint, vbMinimizedNoFocus)
End Sub
同样,如果条形码可能包含任何空格(如Excel integration:上的ZINT wiki页面所示),也可以引用条形码


编辑:您在
/K
标志后也缺少一个空格,但我认为您甚至不需要在此处使用cmd.exe。

为了帮助其他人解决同样的问题,这里是我的工作代码

Private Sub cmdTest_Click()
    Dim strZintPath, strImagePath, strToPrint, strInfoBarcode As String

    strZintPath = Get32BitProgramFilesPath() & "\Zint\"
    strImagePath = CurrentProject.Path & "\images\barcode\"
    strInfoBarcode = "699"

    strToPrint = strZintPath & "zint.exe -b 58 -o " & Chr(34) & strImagePath & strInfoBarcode & ".png" & Chr(34) & " --vers=10 -d " & Chr(34) & strInfoBarcode & Chr(34)
    Call Shell(strToPrint, vbMinimizedNoFocus)
端接头

这就是我从中复制的函数


程序文件中是否缺少空格?猜测这只是一个输入错误,但您应该在任何路径周围加上引号,并加上空格。在
/K
是之后连接字符串时,您缺少空格。。。我忘记在/K之后添加空格,但这并没有解决zint路径问题。仍然是相同的错误。我使用
%ProgramFiles%
作为C:\Program Files\的环境变量。我尝试了上面的代码,但仍然显示相同的错误。我将检查上面的链接。我的错误-我不是Shell的大用户。关于引用任何可能包含空格的参数的一般要点适用于……我已经阅读了上面的链接,并从Shell命令中删除了
cmd.exe/S/K
命令。谢谢你指出了正确的方向。也可以从中找到帮助。如何通知我的新工作代码?我可以编辑上面的问题吗?
Function Get32BitProgramFilesPath() As String
    If Environ("ProgramW6432") = "" Then
       '32 bit Windows
       Get32BitProgramFilesPath = Environ("ProgramFiles")
    Else
       '64 bit Windows
       Get32BitProgramFilesPath = Environ("ProgramFiles(x86)")
    End If
End Function