I have some code that saves the active worksheet as a tab delimited text file, however the cell data that has a comma character in them gets exported with quotation marks, like
John Hopkins, Burgers
becomes
"John Hopkins, Burgers"
How can I work around this?
This is my code:
ActiveWorkbook.SaveAs ActiveWorkbook.path & "\" & filename,
FileFormat:=xlText, CreateBackup:=False
Adding this: I just found out that if I save the file again it removes all "". Can I add an additional save to the code?
I found the following: Go to Start>Settings>Regional And Language Options. Click on the Customize button. Next to List Separator type in a semi-colon (;)
read more to Save As the file is the F12 key. In VBA, too, we can save the file as “Save As.”
I solved it! Since the quotes disappear when you save it manually as a delimited file but not when you use
ActiveWorkbook.SaveAs ActiveWorkbook.path & "\" & filename,
FileFormat:=xlText, CreateBackup:=False
I just added another save after the above one, but this time using the sendkey strokes to mimick the manual method.
ActiveWorkbook.SaveAs fil, FileFormat:= _ xlText
SendKeys "^{F4}"
SendKeys "{ENTER}"
SendKeys "{ENTER}"
According to FileFormat Property, you have the following formats to choose from:
xlCSV
xlCSVMac
xlCSVMSDOS
xlCSVWindows
Why don't you choose one of the comma- separated value formats?
Try xlCSV
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With