Sub 保存文本文件()
Dim sfname As String
sfname = Application.InputBox(prompt:="请输入文本文件的名称", _
Title:="输入文件名称", Type:=2)
If afname = "False" Or sfname = "" Then Exit Sub
sfname = ThisWorkbook.Path & "\" & sfname & ".txt"
On Error Resume Next
If Len(Dir(sfname, vbDirectory)) > 0 Then
If MsgBox("该文件已经存在,是否删除?", vbQuestion + vbYesNo) = vbYes Then
Kill sfname
Else
Exit Sub
End If
End If
On Error GoTo 0
Set ws1 = Worksheets("Sheet1")
ActiveWorkbook.SaveAs Filename:=sfname, FileFormat:=xlCSV
MsgBox "保存成功!"
ActiveWorkbook.Close savechanges:=False
End Sub
06-27
1620
07-16