VB6打开文件CommonDialog用法
目录
1、打开任意文件【第一种】
1Private Sub Command1_Click()
2 Dim x As Long
3 CommonDialog1.ShowOpen
4 x = Shell("explorer.exe " & CommonDialog1.FileName, 1)
5 If x > 0 Then
6 MsgBox "执行成功,程序ID为:" & x
7 End If
8End Sub
2、指定打开某后涰【第二种】
1Private Sub Command2_Click()
2On Error GoTo userCanceled
3With CommonDialog1
4.FileName = ""
5.InitDir = App.path
6.CancelError = True
7.Filter = "文本文件(*.txt)|*.txt"
8'多种类型 .Filter = "PKCS12(*.PFX;*.P12)|*.PFX;*.P12" '文件类型
9.ShowOpen
10End With
11Text1.Text = App.path & "\" & CommonDialog1.FileTitle '修改此处,不带路径,只显示文件名和后缀名
12userCanceled:
13End Sub