gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 19:24:07 24 4
gpt4 key购买 nike

我的目标是避免来自 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com