Results 1 to 4 of 4

Thread: Converting Excel File to CSV

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi Slicemahn!
    Sub Create_CSV()
    Dim fname As String
    Dim LText As String
    Dim CSText As Variant
    Dim myRange As Range, I, j
    fname = ThisWorkbook.path & "\ExportData" & ".csv"
    Open fname For Output As #1
    With ActiveSheet
        Set myRange = .Range("Report")
        For I = 1 To myRange.Rows.Count
            For j = 1 To myRange.Columns.Count
                If InStr(myRange.Cells(I, j), ",") > 0 Then
                    CSText = "" & myRange.Cells(I, j) & ""
                    LText = LText & CSText
                    CSText = ""
                Else
                    LText = IIf(j = 1, "", LText & ",") & myRange.Cells(I, j)
                End If
            Next j
            Print #1, LText
        Next I
    End With
    Close #1
    MsgBox "All complete!", vbInformation, "Data to CSV Format"
    End Sub
    Last edited by 大灰狼1976; 05-16-2019 at 09:25 PM.

Posting Permissions

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