运行时错误'52'与Dir $函数错误的文件名或编号

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

运行时错误'52'错误的文件名或编号

首先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