vba - 检查 7-Zip(64/32 位)的正确安装

标签 vba 7zip

我的目标是避免来自 VBA 调试器的错误消息。需要检查安装了哪个版本的 7-zip,program files/or program files (x86):

尝试做简单的“IF”函数。

Dim PathZipProgram As String
strCommand As String

PathZipProgram = "C:\Program Files(x86)\7-Zip\7z.exe"
If Right(PathZipProgram, 1) Then
    PathZipProgram = PathZipProgram
Else
    PathZipProgram = "C:\Program Files\7-Zip\7z.exe"
End If

Shell strCommand

strCommand = """" & PathZipProgram & """ a -tzip """

VBA 找不到 7zip。

最佳答案

您可以使用这样的函数检查文件是否存在:

Function FileExists(FilePath As String) As Boolean
Dim TestStr As String
    TestStr = ""
    On Error Resume Next
    TestStr = Dir(FilePath)
    On Error GoTo 0
    If TestStr = "" Then
        FileExists = False
    Else
        FileExists = True
    End If
End Function

然后在你的代码中使用它:

Dim PathZipProgram As String
Dim strCommand As String

PathZipProgram = "C:\Program Files(x86)\7-Zip\7z.exe"

If Not FileExists(PathZipProgram) Then
    PathZipProgram = "C:\Program Files\7-Zip\7z.exe"
End If

Shell strCommand

strCommand = """" & PathZipProgram & """ a -tzip """

希望这有助于作为一个起点。

关于vba - 检查 7-Zip(64/32 位)的正确安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55673833/

相关文章:

winapi - 如果源文件打开,CopyFile 和 CopyFileEx 是否工作?

excel - 如何使用 VBA 将文件上传到 OneDrive Business (Sharepoint)

C# - 如何使用 7-zip 库(即不是 .7z,而是 .zip)创建常规 ZIP 存档?

python - 如何从 7z 压缩的文本文件中读取?

c++ - 如何压缩文件夹使用 lzma sdk?

android - 如何提取Android NDK包?

excel - 如何使用 Excel VBA 打开 Outlook excel 附件,在特定时间范围内发送到特定 Outlook 文件夹?

excel - 如何根据条件附加到文本

vba - Excel-VBA 将字符串转换为拼音字母

jar - 正确解码 zip 条目文件名——CP437、UTF-8 还是?