Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 14th, 2005, 03:57 AM
Authorized User
 
Join Date: Jul 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replacing characters in external csv file

Background:
Get file attachement from Outlook, and I need to firstly replace all commas "," with full stops "." and then all semicolons ";" with commas ",".

I am stuck with Replace function / expression...

Thanx in advance

 
Old July 14th, 2005, 10:44 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Is there a replace function? I would do this:

1. Open file
2. Read each line
3. Split each line into an array using the "," as the split character
4. Recreate each line using the "." character
5. Write each line back to a new file (to preserve the old file)

Something like this:

'----------

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("C:\data.csv") Then
    Set objStream = fso.OpenTextFile("C:\data.csv", 1, False, 0)
End If

    Set objCopy = fso.CreateTextFile("C:\newdata.csv")

Do While Not objStream.AtEndOfStream
    strOldLine = objStream.ReadLine
    i = 1
    NewArray = Split(strOldLine, ",")
       strNewLine = NewArray(0)

    Do Until i = UBound(NewArray) + 1
     strNewLine = strNewLine & "." & NewArray(i)
     i = i + 1
    Loop

    objCopy.WriteLine strNewLine

Loop

'----------

This is tested code and it works. It will keep any double quotes intact if there are any (there usually are in csv files).

HTH

mmcdonal
 
Old July 15th, 2005, 01:39 AM
Authorized User
 
Join Date: Jul 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx mmcdonald,

This seems to do the job just as you described.

Great, have a nice summer
Axxess






Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing multiple characters in a string philboparker BOOK: XSLT Programmer's Reference, 2nd Edition 0 May 20th, 2008 04:38 PM
Separating strings and replacing characters sunrain XSLT 4 April 7th, 2008 09:33 AM
Replacing characters in a string semilemon C# 2005 2 June 16th, 2006 11:31 PM
refreshing external js file fs22 Javascript How-To 1 June 17th, 2004 05:02 PM
Opening file external kaivanrijswijk VBScript 0 March 29th, 2004 05:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.