这有一个示例:
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
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Function StartDoc(DocName As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
'change "Open" to "Explore" to bring up file explorer
'StartDoc返回数值31时,没有可打开的应用程序
StartDoc = ShellExecute(Scr_hDC, "Open", DocName, "", "", 1)
'ShellExecute:lpOperation有三个参数:"Open" ,"Explore","Print";
'当使用"Open"时,可对文件、程序等直接打开或运行;对文件夹,按"我的电脑"方式打开
'当使用"Explore"时,对文件,程序不起作用;对文件夹,按资源管理器方式打开.
'以下两行可以直接使资源管理器进入指定路径,并自动打开管理器
'DocName = "D:\Microsoft Office\Templates"
'StartDoc = ShellExecute(Scr_hDC, "Explore", DocName, "", "", 1)
End Function
'对话框按钮返回"DocName"调用字符串
Private Sub Command1_Click()
Dim r As Long
r = StartDoc(Trim(Text1.Text))
End Sub
查一下ShellExecute这个API函数!试一下
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