[COLOR="Navy"]Sub[/COLOR] SaveFile()
[COLOR="Navy"]Dim[/COLOR] ans [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] sSaveAsFilePath [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]On[/COLOR] [COLOR="Navy"]Error[/COLOR] [COLOR="Navy"]GoTo[/COLOR] ErrHandler:
sSaveAsFilePath = "C:\Users\Public\test.txt"
[COLOR="Navy"]If[/COLOR] Dir(sSaveAsFilePath) <> "" [COLOR="Navy"]Then[/COLOR]
ans = MsgBox("File " & sSaveAsFilePath & " exists. Overwrite?", vbYesNo + vbExclamation)
[COLOR="Navy"]If[/COLOR] ans <> vbYes [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
[COLOR="Navy"]Else[/COLOR]
Kill sSaveAsFilePath
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
Sheet7.Copy [COLOR="SeaGreen"]'//Copy sheet 7 to new workbook[/COLOR]
ActiveWorkbook.SaveAs sSaveAsFilePath, xlTextWindows [COLOR="SeaGreen"]'//Save as text (tab delimited) file[/COLOR]
[COLOR="Navy"]If[/COLOR] ActiveWorkbook.Name <> ThisWorkbook.Name [COLOR="Navy"]Then[/COLOR] [COLOR="SeaGreen"]'//Double sure we don't close this workbook[/COLOR]
ActiveWorkbook.Close [COLOR="Navy"]False[/COLOR]
[COLOR="Navy"]End If[/COLOR]
My_Exit:
[COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
ErrHandler:
MsgBox Err.Description
[COLOR="Navy"]Resume[/COLOR] My_Exit
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]