VBA - Save As Text (Tab Delimited)

bvbull200

New Member
Joined
Jul 29, 2013
Messages
24
I have inherited a workbook that is in need of some maintenance. There is one area where I'm a little stumped.

At the end of the macro I am working on, I need it to save a single sheet as a Text (Tab Delimited) file.

The macro that I inherited contains this:

Code:
fname = Application.GetSaveAsFilename(fileFilter:="Excel Files (*.xlsx), *.xlsx", Title:="Save As")    
    If fname <> False Then
        wbDMTOutput.SaveAs (fname)
    End If

That pops up a "Save As" dialogue box, but forces the file to be saved as a .xlsx. Since I now want it to be a .txt file, I originally modified it to this:

Code:
fname = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt", Title:="Save As")
    
    If fname <> False Then
        wbDMTOutput.SaveAs (fname)
    End If

The .txt that it saves it as, however, is really screwy. Weird characters abound and it isn't formatted the same as if I were to manually open the workbook, click Save As, and choose Text (Tab Delimited) and save the file myself. I don't know why that is, but it appears to be trying to save a whole workbook instead of a sheet?

To see if I could get an output that at least worked, I did this code:

Code:
 BaseFolder = "C:\Users\p_bryan\Documents\"
      Filename = "TestTabDelimitedVBA" 'File name with no Extension.
      Extn = ".txt"
    ActiveWorkbook.SaveAs Filename:=BaseFolder & Filename & Extn, _
    FileFormat:=xlText, CreateBackup:=True

The file that it output with that code is perfect. Formatted correctly, no strange characters, etc.

The problem is that it can't be used in a workbook that will be accessed by multiple users since the file path is different for everyone.

What I'm graciously requesting help with is to have a prompt like the first code provides that allows the user to select where the file will be saved, but have it save in the xlText format that I utilized in the third code.

This would let every user put the file where they want and ensure that the saved file is in the proper format.

I hope this makes sense.

I thank you for your consideration of my dilemma and appreciate all assistance!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Cross posted https://www.excelforum.com/excel-programming-vba-macros/1226698-save-as-text-tab-delimited.html

Cross-Posting
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Cross posted https://www.excelforum.com/excel-programming-vba-macros/1226698-save-as-text-tab-delimited.html

Cross-Posting
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.


My apologies. I posted here first, there second.

Did not meant to offend.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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