Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Want to thank those people who have made this forum such a valuable place to visit each day..."

Geography

Where in the world do Tek-Tips members come from?

convert XLS file to CSV file using VBS removing the comma separator

talss21 (TechnicalUser)
22 Jun 12 6:11
Hi

I need the xls file to CSV by removing the comma separator and replace it with tilda as my field contains comma into it .



Set lstArgs = WScript.Arguments
For I = 0 to lstArgs.Count - 1 ' Loop through each file

FullName = lstArgs(I)
FileName = Left(lstArgs(I), InStrRev(lstArgs(I), ".") )

' Create Excel Objects
Set objWS = CreateObject("Excel.application")
set objWB = objWS.Workbooks.Open(FullName)


objWS.application.visible=false
objWS.application.displayalerts=false
'MsgBox FileName
objWB.SaveAs FileName & "csv", 23
objWB.SaveAs
objWS.Application.Quit
objWS.Quit

' Destroy Excel Objects
Set objWS = Nothing
set objWB = Nothing

Next

Please help !
tedsmith (Programmer)
22 Jun 12 7:45
Try the Replace Function?
Eg
FullName = Replace(FullName,Chr(44),"~") will replace all commas with the Tilde
SkipVought (Programmer)
22 Jun 12 8:51

Then can you REALLY say that you have a .CSV (COMMA Separated Values) file, if the delimiters are not COMMAs?

You want to make a TEXT file, pure and simple.

Semantics, but important.

Not all text files are .csv (COMMA Separated Values) but ALL .csv are text files.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

jges (TechnicalUser)
22 Jun 12 9:59
If you have any control over the creation of the CSV file, wrap each value in double quotes. So instead of:

CODE

Value1, Value2, with comma, Value3
you get the more manageable:

CODE

"Value1", "Value2, with comma", "Value3"

Assuming you do not have control over the CSV creation:
The replace function will indeed replace all the commas, but the problem is it will replace all the commas. Instead of:

CODE

Value1, Value2, with comma, Value3
you will have:

CODE

Value1~ Value2~ with comma~ Value3
and you will essentially be back where you started.

Is there a pattern to the data? If so, you might be able to use a regular expression to determine which commas need to be replaced and which need to be kept.
strongm (MIS)
29 Jun 12 8:44
Try changing

objWB.SaveAs FileName & "csv", 23

to

objWB.SaveAs FileName & "csv", 20 ' xlTextWindows

Now your seperator is a TAB, and commas in fields are preserved
strongm (MIS)
2 Jul 12 9:35
talss21 - was any of this of any assistance?
jges (TechnicalUser)
13 Jul 12 10:33
no news is good news?
dilettante (MIS)
15 Jul 12 17:08
This is VBScript anyway, so responding at all is inappropriate.

There is a proper forum for that.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close