Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel export delimiter

Posted on 2002-07-04
14
Medium Priority
?
508 Views
Last Modified: 2010-05-18
I have a situation where a user wants to type information into columns within a spreadsheet and that information needs to be saved as a csv file.

This is easy, however, I need to change the delimiter to be a + char instead of a , char for reasons of the importation of the csv file into another system.

How do I do this?

Thanks,

Emma
0
Comment
Question by:ems_place
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +6
14 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 7130240
how about this, it changes the comma separators, but leaves commas within quotes marks

Private Sub SwapSeperator()
Dim bOn As Boolean
Dim b() As Byte
Dim c As Long

Open "c:\download\gram.csv" For Binary As #1
ReDim b(LOF(1) - 1)
Get #1, , b

For c = 0 To UBound(b)
    If Chr(b(c)) = """" Then
        bOn = Not bOn
        ElseIf Not bOn And Chr(b(c)) = "," Then
        b(c) = Asc("+")
    End If
Next
   
Open "c:\download\gram2.csv" For Binary As #2

Put #2, , b

Close #1, #2

End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7130352
What about this:

Private Sub Form_Load()
Dim sContents As String
Dim ff As Integer

ff = FreeFile
Open "c:\dmyfile.csv" For Input As #ff
    strcontents = Input(LOF(ff), 1)
Close #ff
strcontents = Replace(strcontents, ",", "+", , , vbTextCompare)

Open "c:\dmyfile.csv" For Output As #ff
    Print #ff, strcontents
Close #ff
End Sub
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7130395
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7130415
Great code but you need to manage too much (to me) excel objects to do a simple job, isn't it?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7130425
Hi Richie,

this is a solution completely from within, and i guess you could simply optimize that code for this specific situation without having to deal with path's file checks or whatsoever.....if you're already in excel why not use it?

:O)Bruintje
(of course just pluggin the excel code ;) )

0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 7130907
Hi!

How about this (esp. if you're using VB5 rather than VB6):

Dim i As Integer, str As String

i = InStr(1, str, ",")

While i <> 0
Mid$(str, i, 1) = "+"
i = InStr(i + 1, Text1.Text, ",")
Wend

'Save the str variable
'...

Simply open the file in binary, load the entire content into str, use the above code, then write str back to the file and save it : )

That's it!

glass cookie : )
0
 
LVL 5

Expert Comment

by:kcm76
ID: 7131265
***This is easy, however, I need to change the delimiter to be a + char instead of a , char for reasons of the importation of the csv file into another system.***



if i've properly understood, after generating the csv file(with delimiter) u want to change the "," with "+", is it not? in that case, simply open the text file in a Editor, NoteTablight or VisualInterdev--select all--find "," --replace with-- "+".

otherwise, what did i miss?.


0
 

Author Comment

by:ems_place
ID: 7131587
Hmm, you're nearly there but a couple of the Excel fields are descriptions that may contain ',' and therefore doing a global replace will change the commas within the descriptions and then the resulting csv file will get very mixed up thinking it has new fields starting when it hasn't.

Is there no way of saying:

Export this Excel file to a csv and set the delimiter to a +
0
 
LVL 5

Expert Comment

by:kcm76
ID: 7131608
try this,

open access database and import the excel sheet. once u imported into access table export the same. there it will ask for delimiter. give "+" there.


KCM

0
 
LVL 5

Expert Comment

by:kcm76
ID: 7131612
The above one is my **PROPOSED ANSWER**
0
 
LVL 44

Expert Comment

by:bruintje
ID: 7131985
***Export this Excel file to a csv and set the delimiter to a + ***

already posted
0
 
LVL 1

Accepted Solution

by:
MartijnB earned 800 total points
ID: 7135501
Hi,

You do not need to write code to parse or change the file.
You can use the "Microsoft Text Driver" to import and export information from any office application.

To tell Excel / Access / any app using this driver how to format the .csv file, you can create a schema.ini file.
All information about this configuration file is here:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q210001 
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q210073

In the .ini you change the delimiter and Excel will do the job for you AND other applications can still read the file.

Martijn
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7990647
Hi ems_place,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept MartijnB's comment(s) as an answer.
    *** the only suggestion that will work with fileds containing embedded commas

ems_place, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8050706
Comment from expert accepted as answer

Computer101
E-E Admin
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question