用vb如何运行文件

用vb如何运行文件,文件是非可执行程序,比如.txt……
不能用shell,会错误

第1个回答  2008-07-03
打开.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)

够了吧。。。
第2个回答  2008-07-02
用shell函数啊!

dim abc
abc = shell("c:\123.txt")

就这样就可以运行了。
第3个回答  2008-07-03
先用shell调用cmd,然后利用cmd来打开txt。

代码:

Private Sub Command1_Click()
Shell "cmd /c start C:\WINDOWS\system32\eula.txt"
End Sub
第4个回答  2008-07-02
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 Sub Form_Load()
ShellExecute Me.hwnd, "OPEN", "C:\abc.txt", vbNullString, vbNullString, SW_SHOW
End Sub
第5个回答  2008-07-02
txt文件能运行吗?是不是其中含有能运行的代码?本回答被提问者采纳
相似回答
大家正在搜