我想你应该去看一下msdn
通用对话框根本就不能保存和打开文件,它只能返回文件名而已!打开文件和保存文件必须有自己做!!
Private Sub Command1_Click()
CommonDialog1.ShowOpen '显示打开文件对话框,这一行不能打开文件Label1.Caption = CommonDialog1.FileName '返回用户选取的文件名称End SubPrivate Sub Command2_Click()
CommonDialog1.ShowSave 《就是这一行,根本不能保存文件!》
’这一行也只能显示保存文件的对话框,而不能保存文件
End SubPrivate Sub Form_Load()
CommonDialog1.Filter = "*.txt"
End Sub
通用对话框根本就不能保存和打开文件,它只能返回文件名而已!打开文件和保存文件必须有自己做!!
Private Sub Command1_Click()
CommonDialog1.ShowOpen '显示打开文件对话框,这一行不能打开文件Label1.Caption = CommonDialog1.FileName '返回用户选取的文件名称End SubPrivate Sub Command2_Click()
CommonDialog1.ShowSave 《就是这一行,根本不能保存文件!》
’这一行也只能显示保存文件的对话框,而不能保存文件
End SubPrivate Sub Form_Load()
CommonDialog1.Filter = "*.txt"
End Sub
Dim strfilename As String
Dim strfile As String
Select Case Index
Case 1
CommonDialog1.Filter = "(*.cao)|*.cao"
CommonDialog1.FilterIndex = 3
CommonDialog1.Flags = cdlOFNFileMustExist
CommonDialog1.ShowOpen
strfilename = CommonDialog1.FileName
If strfilename <> "" Then
Open strfilename For Binary As #1
strfile = Input(LOF(1), 1) '将文件读入到变量
'Debug.Print strfile
Close #1
Case 2 '选择保存
CommonDialog1.Filter = "(*.cao)|*.cao"
CommonDialog1.FilterIndex = 3
CommonDialog1.Flags = &H2
CommonDialog1.ShowSave
strfilename = CommonDialog1.FileName
strfile=。'将信息写入变量
If strfilename <> "" Then
Open strfilename For Output As #1
Print #1, strfile '将变量内容写入文件 Close #1