添加一个文件打腊斗开对话正斗框,在工程--部件中选择
CommonDialog1.DefaultExt 扩展名
CommonDialog1.InitDir 路径
CommonDialog1.Filter 文件过滤轮清磨,按扩展名
CommonDialog1.ShowOpen 文件打开
如果是通过双击文档打开的,那么文件名是储存在Command这个变答仔量中的,通宴举碰过分析这个变量就能得到路径,比如:
Dim d() As String, s As Stringd = Split(Command, "/")
d(Ubound(d)) = "晌谈"
s = Join(d, "/")
MsgBox "路径为" & s
能说清楚点吗?如果是EXE,DLL等可执行文件,Shell就可以拆扒了
Shell "此高C:\A.EXE",vbNomalFocus
如果是已知打开方式的文件,Shell打开文件的程序+文件
如打开TXT文件
Shell "C:\Windows\notepad.exe C:\A.TXT",vbNomalFocus
如果是其他旅扒昌文件就要调用API,假设打开A.BCD
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
Sub Main()
Dim Fe
Fe = "C:\A.BCD"
ShellExecute Me.hWnd, "open",Fe,Fe, vbNull, 3
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)