Question about saving to text delimited file

srosk

Board Regular
Joined
Sep 17, 2018
Messages
132
Hi there. I have the following, which saves the current tab as 12.txt.

Is there a way to specify the path? Is there a way to make it stop and not overwrite the file / prompt a message if 12.txt already exists in the location?

And finally, I notice that when it saves, it basically closes out the macro and then the active file is 12.txt. I want to save my results on the macro file first, so to combat this, do I need to first save the macro, then execute a modified version of the following file? Is there a way to close the txt file and automatically re-open my macro? Maybe I'm missing something though?


Code:
ThisWorkbook.SaveAs "12", FileFormat:=xlTextWindows
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this instead
Code:
If Not (Application.Dialogs(xlDialogSaveAs).Show("12", 3)) Then
    MsgBox "user cancel"
End If

Fiddle with the 3 if the default format isn't exactly what you want.
 
Last edited:
Upvote 0
This is good, thank you. Is there a way to specify the folder location?

Also, once I hit save, excel exits 1231.xlsm and enters 12.txt. Is it possible to prevent that from happening? Would like to keep the macro active.
 
Upvote 0
Instead of "12" use your full path: "C:\Some\Directory\12.txt"
There's probably a close statement for the macro, look for ".Close" in the code till you find it. You could comment that line out if you want.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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