2017-04-03 33 views
1

chrome.exeファイルが存在するかどうかを確認し、そうであればブラウザを開きます。私が最初にIf確認の上

実行時エラー '52' 不正のファイル名または番号

を取得しています。何故ですか?

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 

答えて

3

ディレクトリの周りにあなたの引用符を削除する - 彼らは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" 

をあなた私はちょうど32ビットにしようとしたものの、Shellコマンドでそれらを必要があるかもしれませんバージョンなしで動作しました:

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 
関連する問題