问题似乎很简单,但我找到的所有解决方案都没有用。
我想知道如何自动打开Chrome,我尝试了下面的代码和其他几个解决方案,但是当Chrome完全关闭并且我尝试打开时,它会显示窗口,但它不会打开任何网站。< / p>
Private Sub Command1_Click()
Shell "C:\Program Files\Google\Chrome\Application\chrome.exe -url https://www.google.com/"
End Sub
答案 0 :(得分:1)
这与VB6没有任何关系,当然,这与Chrome命令行开关有关。 Chrome命令行开关以两个破折号开头。所以这应该有效:
Shell "C:\Program Files\Google\Chrome\Application\chrome.exe --url https://www.google.com/"
(Program Files (x86)
,如果您正在运行64位Windows,自然而然)
但是你不需要为url指定开关,这也有效:
Shell "C:\Program Files\Google\Chrome\Application\chrome.exe https://www.google.com/"
修改强>
实际上似乎没有Chrome的'url'开关,因此只需将url放在命令行上就可以了,就像我上面的第二个shell命令一样。
答案 1 :(得分:1)
您应该确保Chrome.exe的安装位置。 32位还是64位? 您必须先检查才能运行它。
例如,我有一台64位计算机,Chrome.exe是32位版本安装在:
C:\ Program Files(x86)\ Google \ Chrome \ Application
以下代码检查32/64位版本:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public Sub OpenChrome(ByVal pURL As String)
Dim sChromePath As String
Dim sTmp As String
Dim sProgramFiles As String
Dim bNotFound As Boolean
'
' check for 32/64 bit version
'
sProgramFiles = Environ("ProgramFiles")
sChromePath = sProgramFiles & "\Google\Chrome\Application\chrome.exe"
If Dir$(sChromePath) = vbNullString Then
' if not found, search for 32bit version
sProgramFiles = Environ("ProgramFiles(x86)")
If sProgramFiles > vbNullString Then
sChromePath = sProgramFiles & "\Google\Chrome\Application\chrome.exe"
If Dir$(sChromePath) = vbNullString Then
bNotFound = True
End If
Else
bNotFound = True
End If
End If
If bNotFound = True Then
MsgBox "Chrome.exe not found"
Exit Sub
End If
ShellExecute 0, "open", sChromePath, pURL, vbNullString, 1
End Sub
Private Sub cmdOpenChrome_Click()
OpenChrome txtUrl.Text
End Sub
以下示例使用了许多不同的浏览器: