打开.doc要先打开Word,打开.dat要先打开 一个能打开视频软件的EXE,其它类似,我已经说了ShellExecute更直接一些,学会用API,我给你一个打开.doc例子: 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 Const SW_SHOW = 5 Private Sub Command1_Click() ShellExecute Me.hwnd, "open", "c:\11.doc", "", "", SW_SHOW End Sub
Attribute VB_Name = "ModOpenFile"Option ExplicitPublic 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 Enum ShowStyle vbHide vbMaximizedFocus vbMinimizedFocus vbMinimizedNoFocus vbNormalFocus vbNormalNoFocus End EnumPublic Function OpenFile(ByVal OpenName As String, Optional ByVal InitDir As String = vbNullString, Optional ByVal msgStyle As ShowStyle = vbNormalFocus) ShellExecute 0&, vbNullString, OpenName, vbNullString, InitDir, msgStyle End Function这个是论坛上一个朋友提供的...(具体谁忘啦..) 可以作为一个模块,调用函数openfile
用命令行最简单不过了! a = Shell("cmd /c "start D:\run.txt"", vbNormalFocus)
returnID = Shell("notepad D:\run.txt", vbNormalFocus)
这样打开.txt可以,但要打开.doc、.dat以及自己注册定义的文件怎么办?也是一样的先打开这个可执行程序吗?可执行的路径有什么要求? 随便放在那里都可以?
谢谢
VB6.0里面怎么没有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 Long
Private Const SW_SHOW = 5
Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "c:\11.doc", "", "", SW_SHOW
End Sub
Public Enum ShowStyle
vbHide
vbMaximizedFocus
vbMinimizedFocus
vbMinimizedNoFocus
vbNormalFocus
vbNormalNoFocus
End EnumPublic Function OpenFile(ByVal OpenName As String, Optional ByVal InitDir As String = vbNullString, Optional ByVal msgStyle As ShowStyle = vbNormalFocus)
ShellExecute 0&, vbNullString, OpenName, vbNullString, InitDir, msgStyle
End Function这个是论坛上一个朋友提供的...(具体谁忘啦..)
可以作为一个模块,调用函数openfile
a = Shell("cmd /c "start D:\run.txt"", vbNormalFocus)
比如打开某个txt文件可以使用:
shell "notepad c:\boot.ini"