+ Reply to Thread
Results 1 to 5 of 5

Marco for save excel sheet as a CSV with semicolon

  1. #1
    Registered User
    Join Date
    11-13-2012
    Location
    Taiwan
    MS-Off Ver
    Excel 2003
    Posts
    9

    Marco for save excel sheet as a CSV with semicolon

    Happy new year to all.

    I have reocrded a marco to save a excel sheet to a csv file as below, however, the default separator is comma, but we need semicolon. I have tried changing the List separator from Control Panel but still failed. Is there anyone can help to modify this marco and add the separator as semecolon?

    ActiveWorkbook.SaveAs Filename:= _
    "c:\MyFile.csv", FileFormat:=xlCSV _
    , CreateBackup:=False
    Last edited by Daniel Chang; 01-06-2013 at 08:54 PM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Marco for save excel sheet as a CSV with semicolon

    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    11-13-2012
    Location
    Taiwan
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Marco for save excel sheet as a CSV with semicolon

    Hi, Thanks for quick reply, it works but the file comes out with
    TWDOLLAR;
    A97101;
    TW1;
    S;
    0.7475;
    0.5;
    DBSTP AFS GVB;
    DTP FO_STY;
    20120816

    While we need it to be TWDOLLAR;A97101;TW1;S;0.7475;0.5;DBSTP AFS GVB;DTP FO_STY;20120816
    Please advise how to adjust the code.

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Marco for save excel sheet as a CSV with semicolon

    attach a sample of input file with also desired result

  5. #5
    Registered User
    Join Date
    11-13-2012
    Location
    Taiwan
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Marco for save excel sheet as a CSV with semicolon

    It's solved by using the following marco.

    Public Sub CharacterSV()
    Const DELIMITER As String = ";"
    Dim myRecord As Range
    Dim myField As Range
    Dim nFileNum As Long
    Dim sOut As String

    nFileNum = FreeFile
    Open "Test.txt" For Output As #nFileNum
    For Each myRecord In Range("A1:A" & _
    Range("A" & Rows.Count).End(xlUp).Row)
    With myRecord
    For Each myField In Range(.Cells, _
    Cells(.Row, Columns.Count).End(xlToLeft))
    sOut = sOut & DELIMITER & myField.Text
    Next myField
    Print #nFileNum, Mid(sOut, 2)
    sOut = Empty
    End With
    Next myRecord
    Close #nFileNum
    End Sub
    Last edited by Daniel Chang; 01-06-2013 at 08:56 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1