shell 函数只可以执行.exe .com .bat 的可执行文件。
ShellExecute 是个api函数,可以执行与Windows系统相关联的文件。比如:
shell "c:\1.doc" 应该报错的,因为shell只能执行.exe .com .bat
应:ShellExecute Me.hwnd, "open", "C:\1.doc", "", "", 0
ShellExecute Me.hwnd, "open", "http://miaozk2006.blog.163.com/blog", "", "", 5
ShellExecute hwnd, "open", "C:\1.xls", vbNull, vbNull, SW_SHOWNORMAL
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
打开文件夹
shell "explorer 文件夹",1
shell "cmd /c start D:\music"
打开d盘下music的文件夹
移动(剪切):shell”cmd /c move c:\1.txt d:\1.txt”
打开网址:
Shell "C:\Program Files\TheWorld 2.0\TheWorld.exe http://miaozk2006.blog.163.com/blog", 1
Shell "explorer.exe http://miaozk2006.blog.163.com/blog", 1
Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE " & strURL, 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
调用系统计算器Shell "calc.exe", 3
调用记事本Shell "NotePad ", vbNormalFocus(打开某个记事本:Shell "NOTEPAD.EXE " & 文档路径, vbNormalFocus)
打开任务管理器:Shell "c:\windows\system32\taskmgr.exe", 1
打开资源管理器:Shell "c:\windows\explorer.exe " & path, 1
注销用户 Shell "shutdown -l"
关闭系统 Shell "shutdown -S -t 0"
重启 Shell "shutdown -R -t 0"
0是代表响应的时间
结束explorer.exe进程
Shell "taskkill /f /im explorer.exe ", vbHide
(结束其它进程也是这样,如:shell "taskkill /f /im ttplayer.exe"
或taskkill /im ttplayer.exe /f)
运行dos命令:
Shell “cmd /c ipconfig /all >C:\result.txt”
Shell “cmd /c move c:\result.txt d:\result.txt”
Shell “cmd /c copy c:\result.txt d:\result.txt”
建立一个空文件Shell "cmd /c echo. > d:\a.txt"
删除一个文件 shell “cmd /c result.txt”
建立一个文件夹 shell “cmd /c md d:\abc\”
删除一个文件夹 shell “cmd /c rd d:\abc”
重命名一个文件 shell “cmd /c ren d:\a.txt b.txt”
用windows关联方式找开文件Shell "cmd.exe /c start " & App.Path & "a.doc"
shell “cmd /c @start iexplore.exe http://miaozk2006.blog.163.com/blog”