这是我另存为的代码:
Private Sub menuSaveAS_Click()
On Error GoTo errorlab '出错调至行标签errlab
CommonDialog1.FileName = "文本1.txt " '设置缺省文件名
CommonDialog1.DefaultExt = "txt " '设置缺省扩展名
CommonDialog1.InitDir = "d:\ " '初始化路径
CommonDialog1.Filter = "Word 文档(*.doc) ¦*.doc ¦文本文件(*.txt) ¦*.txt ¦所有文件(*.*) ¦*.* "
CommonDialog1.FilterIndex = 1
CommonDialog1.CancelError = True
CommonDialog1.ShowSave
Open savefilename For Output As #1
Print #1, Text1.Text
Close #1
errorlab:
End Sub
这个代码就是你一点它,就是都会弹出保存对话框,
而保存要求的是第一次点它是会出现保存对话框,而已经保存过后,你再点保存时,则不会弹出保存对话框
我的保存代码是这样:
Private Sub menuSave_Click()
If savefilename <> " " Then
Open savefilename For Output As #1
Print #1, Text1.Text
Close #1
Else
Call menuSaveAS_Click
End If
End Sub 其中把savefilename 设为全局变量,并且savefilename=commondialog1.filename当保存过时,savefilename
不为空,如果为空,则没保存
Private Sub menuSaveAS_Click()
On Error GoTo errorlab '出错调至行标签errlab
CommonDialog1.FileName = "文本1.txt " '设置缺省文件名
CommonDialog1.DefaultExt = "txt " '设置缺省扩展名
CommonDialog1.InitDir = "d:\ " '初始化路径
CommonDialog1.Filter = "Word 文档(*.doc) ¦*.doc ¦文本文件(*.txt) ¦*.txt ¦所有文件(*.*) ¦*.* "
CommonDialog1.FilterIndex = 1
CommonDialog1.CancelError = True
CommonDialog1.ShowSave
Open savefilename For Output As #1
Print #1, Text1.Text
Close #1
errorlab:
End Sub
这个代码就是你一点它,就是都会弹出保存对话框,
而保存要求的是第一次点它是会出现保存对话框,而已经保存过后,你再点保存时,则不会弹出保存对话框
我的保存代码是这样:
Private Sub menuSave_Click()
If savefilename <> " " Then
Open savefilename For Output As #1
Print #1, Text1.Text
Close #1
Else
Call menuSaveAS_Click
End If
End Sub 其中把savefilename 设为全局变量,并且savefilename=commondialog1.filename当保存过时,savefilename
不为空,如果为空,则没保存
加个
savefilename=CommonDialog1.filename
'加这么一句,看看savefilename的值正确不,然后查找原因
msgbox savefilename
exit sub
'结束
If savefilename <> " " Then
Open savefilename For Output As #1
Print #1, Text1.Text
Close #1
Else
Call menuSaveAS_Click
End If
End Sub
Private savefilename As String
Private Sub menuSaveAS_Click()
On Error GoTo errorlab '出错调至行标签errlab
CommonDialog1.FileName = "文本1.txt " '设置缺省文件名
CommonDialog1.DefaultExt = "txt " '设置缺省扩展名
CommonDialog1.InitDir = "d:\ " '初始化路径
CommonDialog1.Filter = "Word文档(*.doc)|*.doc|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.CancelError = True
CommonDialog1.ShowSave
savefilename = CommonDialog1.FileName
Open savefilename For Output As #1
Print #1, Text1.Text
Close #1
errorlab:
End SubPrivate Sub menuSave_Click()
If savefilename <> "" Then
Open savefilename For Output As #1
Print #1, Text1.Text
Close #1
Else
Call menuSaveAS_Click
End If
End SubPrivate Sub Command1_Click()
menuSave_Click
End Sub
Private Sub Command2_Click()
menuSaveAS_Click
End Sub