Results 1 to 4 of 4

Created a CSV file using macros but when exported to excel contains special character

Threaded View

  1. #1
    Registered User
    Join Date
    09-19-2008
    Location
    Singapore
    Posts
    41

    Unhappy Created a CSV file using macros but when exported to excel contains special character

    Hi All,

    I have written a macro to create a csv file. What I am doing is to write the data into the columns and then saving the file as "CSV". But now when I am trying to open the CSV using the export external data option in excel its displaying special characters as the data content.

    But when I open the file by double clicking on it the data is rendered correctly.
    Please help. Attaching the code below.

    Sub splitLogExtract()
    
        Dim temp_i As Integer
        Dim temp_j As Integer
        Dim temp_k As Integer
        Dim newbook As Workbook
        Dim newsheet As Worksheet
        Dim firstline As Boolean
        Dim temp_sheet As Integer
        Dim fs As FileSystemObject
        
        For temp_i = 1 To NumUniqueIssueType
            Let temp_sheet = 0
            Set fs = CreateObject("Scripting.FileSystemObject")
            If Not fs.fileExists("D:\SMS\" & UniqueIssueTypeList(temp_i) & ".csv") Then
                Set newbook = Workbooks.Add
                With newbook
                    .Title = ""
                    .Subject = ""
                    .SaveAs Filename:="D:\SMS\" & UniqueIssueTypeList(temp_i) & ".csv"
                End With
                newbook.Save
                newbook.Close
            Else
                Kill ("D:\SMS\" & UniqueIssueTypeList(temp_i) & ".csv")
                Set newbook = Workbooks.Add
                With newbook
                    .Title = ""
                    .Subject = ""
                    .SaveAs Filename:="D:\SMS\" & UniqueIssueTypeList(temp_i) & ".csv"
                End With
                newbook.Save
                newbook.Close
            End If
            Set newbook = Workbooks.Open("D:\SMS\" & UniqueIssueTypeList(temp_i) & ".csv")
            'For temp_j = 1 To NumUniqueIssueType
            For temp_k = 1 To NumDataLine
                If issueTypeList(temp_k) = UniqueIssueTypeList(temp_i) Then
                    temp_sheet = temp_sheet + 1
                    Call WriteCell(temp_k, temp_sheet)
                End If
            Next 'temp_k NumDataLine
            'Next 'temp_j NumUniqueIssueType
            MsgBox ("temp_sheet: " & temp_sheet)
            newbook.Save
            newbook.Close
        Next 'temp_i NumUniqueIssueType
    End Sub
    
    Sub WriteCell(ByVal NumLine As Integer, ByVal LineNum As Integer)
    
        Dim temp_i As Integer
        
        For temp_i = 1 To 50
            Cells(LineNum, temp_i) = DataLine(temp_i, NumLine)
        Next
    End Sub
    Last edited by Aswathy; 10-23-2008 at 02:48 AM.

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