使用Common Dialog Control这个控件,中文是“通用对话框控件”通过菜单的“工程”-》“部件...”来选择加入到工程中随后设置CancelError的属性为True,即表示用户点击取消会产生错误。在一个按钮下输入代码: Private sub Command1_Click() On Error Goto ErrL:Err.clear With CommonDialog1 .Filter = "所有文件(*.*)|*.*" .ShowOpen Msgbox "用户点的文件为:" & vbcrlf & .FileName,vbInformation End With ErrL: Msgbox "用户点击了取消!",vbInformation End Sub
//某一类文档关联我得程序打开 我得程序会用shell调用相应的应用程序来打开这个文档 请问我怎么获得这个文档的文件名?在窗体的load事件中处理: Private Sub Form_Load() MsgBox Command 'command返回一个字串,你处理这个字串就可以了,前提是要设置好文件关联 End Sub
Private sub Command1_Click()
On Error Goto ErrL:Err.clear
With CommonDialog1
.Filter = "所有文件(*.*)|*.*"
.ShowOpen
Msgbox "用户点的文件为:" & vbcrlf & .FileName,vbInformation
End With
ErrL:
Msgbox "用户点击了取消!",vbInformation
End Sub
下面要加一句: Exit Sub
Private Sub Form_Load()
MsgBox Command 'command返回一个字串,你处理这个字串就可以了,前提是要设置好文件关联
End Sub