PDA

View Full Version : [SOLVED:] Save Workbook As .txt File With Delimiter



endri
07-17-2016, 03:17 AM
Hi,
i have the following code which saves the entire workbook in a text file. That's ok, but i want to add also a delimiter between cells content of the same row(otherwise from column to column). Hope anyone can help me!
Thank you!

The code is:

"ActiveWorkbook.SaveAs Filename:="C:\filepath\example.txt", _
FileFormat:=xlUnicodeText, CreateBackup:=False"

mdmackillop
07-17-2016, 03:50 AM
Why not save as CSV?

endri
07-17-2016, 04:23 AM
Because i need the txt file to use it with another broadcast software, which requires specifically the file to be .txt.

mdmackillop
07-17-2016, 04:33 AM
Tweaking Snb's answer to your previous question

Sub M_snb()
Cells.Copy
With GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.GetFromClipboard
CreateObject("scripting.filesystemobject").createtextfile("C:\testdir\new1.txt").write .GetText
End With
End Sub

snb
07-17-2016, 04:49 AM
Did you ever use the macrorecorder ??

endri
07-17-2016, 05:07 AM
No, i never need it really. I am just having troubles about configuring a specific broadcast software. That's why i really appreciate your help and patience. I apologize for my "ignorance" in this field. Thank you again!

endri
07-17-2016, 05:49 AM
Hi again,
the script works fine but it inserts no delimiter. Thnx for your patience!

Paul_Hossler
07-17-2016, 06:12 AM
1. You didn't say which delimiter, so I'm guess a comma

2. 'Specifically requires txt' is ambiguous, so I'm guessing that the file extension has to be ".txt" so I'm guessing that a CSV file labeled with a txt extension is OK

3. The file extension can be different that the internal file contents and sometimes it's OK

4. This if from the macro recorder, but edited a little



Option Explicit

Sub Macro1()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"CSV_but_Looks_Like_TXT.txt", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Save
Application.DisplayAlerts = False
ThisWorkbook.Close False
ActiveWorkbook.Save
End Sub




(remove the .zip part since you can't upload .txt file and I had to fool the system)

endri
07-17-2016, 07:00 AM
Thank you Paul!

Paul_Hossler
07-17-2016, 07:39 AM
I think this is a little simpler; for some reason (probably due to my insufficient editing of the recorder code) some lines were left in




Option Explicit

Sub Macro1()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="CSV_but_Looks_Like_TXT.txt", FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = True
ThisWorkbook.Close False
End Sub

snb
07-17-2016, 08:07 AM
The only code you need:


Sub M_snb()
ThisWorkbook.SaveAs "G:\snb_000.txt", 23
ThisWorkbook.Close 0
End Sub