从 Access 调用 Zint VBA
Call Zint from Access VBA
我将在我的 Access 程序中使用 ZINT 作为我的条形码生成器。
我想在 Access VBA 中使用 SHELL 命令调用它。我的问题是,我无法从命令提示符调用 ZINT。
这是我的代码。
Private Sub cmdTest_Click()
Dim strToPrint, strInfoBarcode As String
strInfoBarcode = "Batch #699"
strToPrint = "%ProgramFiles%\zint\zint.exe -o c:\path9.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 调用 ZINT 程序的正确方法 VBA?
您是否在 Program Files
中缺少 space?我猜这只是一个打字错误,但您应该在任何带有 space.
的路径周围加上引号
Private Sub cmdTest_Click()
Dim strToPrint, strInfoBarcode As String
strInfoBarcode = "Batch #699"
strToPrint = """%ProgramFiles%\zint\zint.exe"" -o c:\path9.png -b 58 --vers=10 -d """ & strInfoBarcode & """"
Call Shell("cmd.exe /S /K " & strToPrint, vbMinimizedNoFocus)
End Sub
同样,如果条形码可能包含任何 spaces(如 Excel 集成的 ZINT wiki 页面所示:http://zint.org.uk/Excel.aspx),也可能是一个好主意。
编辑:您在 /K
标志后还遗漏了一个 space,但我认为您甚至不需要在这里使用 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)
结束子
这是我从 Get Path of Program Files
复制的函数
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
我将在我的 Access 程序中使用 ZINT 作为我的条形码生成器。 我想在 Access VBA 中使用 SHELL 命令调用它。我的问题是,我无法从命令提示符调用 ZINT。 这是我的代码。
Private Sub cmdTest_Click()
Dim strToPrint, strInfoBarcode As String
strInfoBarcode = "Batch #699"
strToPrint = "%ProgramFiles%\zint\zint.exe -o c:\path9.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 调用 ZINT 程序的正确方法 VBA?
您是否在 Program Files
中缺少 space?我猜这只是一个打字错误,但您应该在任何带有 space.
Private Sub cmdTest_Click()
Dim strToPrint, strInfoBarcode As String
strInfoBarcode = "Batch #699"
strToPrint = """%ProgramFiles%\zint\zint.exe"" -o c:\path9.png -b 58 --vers=10 -d """ & strInfoBarcode & """"
Call Shell("cmd.exe /S /K " & strToPrint, vbMinimizedNoFocus)
End Sub
同样,如果条形码可能包含任何 spaces(如 Excel 集成的 ZINT wiki 页面所示:http://zint.org.uk/Excel.aspx),也可能是一个好主意。
编辑:您在 /K
标志后还遗漏了一个 space,但我认为您甚至不需要在这里使用 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)
结束子
这是我从 Get Path of Program Files
复制的函数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