private sub command1_click() shell "explorer " & text1.text end sub
既然大家都提供了有效方法了,那么我就说另一个有效方法。使用API函数 ShellExecute 例子看下面: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 LongPrivate Sub Lab_Lab_Click() Dim ret& ret& = ShellExecute(Me.hwnd, "Open", "http://www.csdn.net", "", App.Path, 1) End Sub
那么要使打开的IE浏览器获得焦点 还要加上explorer.gotfocus 是么?
'声明API函数:ShellExecute public 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 private sub command1_click() ShellExecute "www.163.com" end sub
shell "explorer " & text1.text
end sub
Dim ret&
ret& = ShellExecute(Me.hwnd, "Open", "http://www.csdn.net", "", App.Path, 1)
End Sub
public 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
private sub command1_click()
ShellExecute "www.163.com"
end sub
不用,ShellExecute 的参数可以将 IE 作为前置窗口显示。