1
我需要檢查一個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