打开.txt而已,何必那么麻烦:
Private Sub Command1_Click()
Dim strpath As String
strpath = "C:\1.txt"
Shell "NOTEPAD.EXE " & strpath, 1 '注意NOTEPAD.EXE后面有个空格
End Sub
如果只想调用系统记事本,可用Shell "NotePad ", vbNormalFocus
调用系统计算器Shell "calc.exe", 3
shell 函数只可以执行.exe .com .bat 的可执行文件。
(打开文件夹也可用shell:
shell "explorer 文件夹",1
shell "cmd /c start D:\music"
打开d盘下music的文件夹)
ShellExecute 是个api函数,可以执行与Windows系统相关联的文件
使用:先声明API
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
打开doc
ShellExecute Me.hwnd, "open", "C:\1.doc", "", "", 0
打开Excel
ShellExecute hwnd, "open", "C:\1.xls", vbNull, vbNull, SW_SHOWNORMAL
打开某个网址:
ShellExecute Me.hwnd, "open", "
http://www.baidu.com", "", "", 5
也可用某个程序来打开某文件,如
Shell "C:\Program Files\TheWorld 2.0\TheWorld.exe
http://www.baidu.com", 1
是用世界之窗浏览器打开百度网址
sub main()
strfilepath = "F:\cp\C\成果\test\t.dsw"
Shell "C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin\MSDEV.EXE " & strfilepath, 1
End Sub
即是用VC++6.0打开dsw文件(启动对象为sub main)
够了吧。。。