Save a sheet as an a tab delimitted text file and close the copy of the sheet if it is saved or if the macro is aborted

nando88

Board Regular
Joined
Jun 22, 2013
Messages
124
I have a save function, that saves a specific sheet as a tab delimitted text file. The sheet is very hidden and it becomes visible only when saving the file and becomes very hidden once again, but if I abort the process, the file stays visible and that is what I wish to avoid.
Can someone please tell me how can I fix this issue?
Thanks in advance.

This is the code that I am currently using:

Sub save()
Application.DisplayAlerts = False
Sheets("Format3").Visible = True
Sheets("Format3").Select
Sheets("Format3").Copy
New_file = InputBox("Ingrese el nombre del archivo que desea salvar", "Archivo a salvar")

Set File_Dialog = Application.FileDialog(msoFileDialogFolderPicker)
File_Dialog.AllowMultiSelect = False
File_Dialog.Title = "Select the Directory to Save the File"
If File_Dialog.Show <> -1 Then
Exit Sub
End If
'ChDir "D:\"
ActiveWorkbook.SaveAs Filename:=File_Dialog.SelectedItems(1) & "\" & New_file & ".txt", FileFormat:=xlText, _
CreateBackup:=False
Application.DisplayAlerts = True
ActiveWorkbook.Close
Sheets("Format3").Visible = xlSheetVeryHidden
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Add this:
VBA Code:
Sheets("Format3").Visible = xlSheetVeryHidden
just before the:
Code:
Exit Sub
and move the same line before:
VBA Code:
ActiveWorkbook.Close

PS. By the way, why are you using:
Code:
Sheets("Format3").Copy
 
Last edited:
Upvote 0
Sorry, update to my previous post. Don't worry about the PS. (I got it) and don't move the line before ActiveWorkbook.Close because it's okay where it is. Just add a copy of it before Exit Sub.
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top