第1个回答 推荐于2016-07-24
这是我以前写记事本程序时的保存和另存为的代码,你看下就明白了:
Private Sub mnusave_Click() '保存
Set fs = CreateObject("Scripting.FileSystemObject")
CommonDialog1.InitDir = "c:\"
CommonDialog1.Filter = "文本文件|*.txt"
If fs.fileexists(FileName) = False Then
CommonDialog1.ShowSave
End If
FileName = CommonDialog1.FileName
RichTextBox1.SaveFile FileName, rtfText
Me.Caption = "Easy Notebook -" & FileName
End Sub
Private Sub mnuanother_Click() '另存为
CommonDialog1.InitDir = "c:\"
CommonDialog1.Filter = "文本文件|*.txt"
CommonDialog1.ShowSave
FileName = CommonDialog1.FileName
RichTextBox1.SaveFile FileName, rtfText
Me.Caption = "Easy Notebook -" & FileName
End Sub
其中FileName是一个Public变量本回答被提问者采纳