gpt4 book ai didi

vba - 运行时错误 '52' 带有 Dir$ 函数的错误文件名或编号

转载 作者:行者123 更新时间:2023-12-04 21:56:39 31 4
gpt4 key购买 nike

我需要检查是否存在 chrome.exe 文件,如果存在,请打开浏览器。我越来越

Runtime error '52' Bad filename or number



在第一个 If查看。这是为什么?
Sub openChrome()
Dim chromePath32
Dim chromePath64
Dim chromePathUser
Dim current_user

chromePath32 = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
chromePath64 = """C:\Program Files\Google\Chrome\Application\chrome.exe"""
current_user = (Environ$("Username"))
chromePathUser = """c:\users\" & current_user & "\AppData\Local\Google\Chrome\Application\Chrome.exe"""

If Dir$(chromePath32) <> "" Then '<-----error here
Shell (chromePath32 & " -url http:google.co.nz")
ElseIf Dir$(chromePath64) <> "" Then
Shell (chromePath64 & " -url http:google.co.nz")
ElseIf Dir$(chromePathUser) <> "" Then
Shell (chromePathUser & " -url http:google.co.nz")
Else
MsgBox "Chrome installation not found"
Exit Sub
End If
End Sub

最佳答案

删除目录周围的引号 - Dir 中不需要它们命令:

chromePath32 = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
chromePath64 = "C:\Program Files\Google\Chrome\Application\chrome.exe"
current_user = (Environ$("Username"))
chromePathUser = "c:\users\" & current_user & "\AppData\Local\Google\Chrome\Application\Chrome.exe"

可能需要他们在 Shell命令,虽然我只是尝试了 32 位版本并且没有它们也可以工作:
If Dir$(chromePath32) <> "" Then
Shell """" & chromePath32 & """ -url http:google.co.nz"
ElseIf Dir$(chromePath64) <> "" Then
Shell """" & chromePath64 & """ -url http:google.co.nz"
ElseIf Dir$(chromePathUser) <> "" Then
Shell """" & chromePathUser & """ -url http:google.co.nz"
Else
MsgBox "Chrome installation not found"
Exit Sub
End If

关于vba - 运行时错误 '52' 带有 Dir$ 函数的错误文件名或编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43193738/

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