Results 1 to 2 of 2

Excel cannot import files with long column and with comma

Threaded View

  1. #1
    Registered User
    Join Date
    05-06-2010
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    1

    Smile Excel cannot import files with long column and with comma

    I have used the following VB script and have some problem to read the long text file ( in attachment file called A1.csv). The 2nd line of data showed only 3 instead of 42 column. Somehow excel did not import data. Also try to ignore the comma (comma=false) but it does not work (sample file B1.csv)
    Please help to look at the script.

    Thank you
    ============script====================
    Sub CombineTextFiles()
        Dim FilesToOpen
        Dim x As Integer
        Dim wkbAll As Workbook
        Dim wkbTemp As Workbook
        Dim sDelimiter As String
    
        On Error GoTo ErrHandler
        Application.ScreenUpdating = False
    
        sDelimiter = "|"
    
        FilesToOpen = Application.GetOpenFilename _
          (FileFilter:="Text Files (*.csv), *.csv", _
          MultiSelect:=True, Title:="Text Files to Open")
    
        If TypeName(FilesToOpen) = "Boolean" Then
            MsgBox "No Files were selected"
            GoTo ExitHandler
        End If
    
        x = 1
        Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
        wkbTemp.Sheets(1).Copy
        Set wkbAll = ActiveWorkbook
        wkbTemp.Close (False)
        wkbAll.Worksheets(x).Columns("A:A").TextToColumns _
          Destination:=Range("A1"), DataType:=xlDelimited, _
          TextQualifier:=xlDoubleQuote, _
          ConsecutiveDelimiter:=False, _
          Tab:=False, Semicolon:=False, _
          Comma:=False, Space:=False, _
          Other:=True, OtherChar:="|"
        x = x + 1
        
        While x <= UBound(FilesToOpen)
            Set wkbTemp = Workbooks.Open(Filename:=FilesToOpen(x))
            With wkbAll
                wkbTemp.Sheets(1).Move After:=.Sheets(.Sheets.Count)
                .Worksheets(x).Columns("A:A").TextToColumns _
                  Destination:=Range("A1"), DataType:=xlDelimited, _
                  TextQualifier:=xlDoubleQuote, _
                  ConsecutiveDelimiter:=False, _
                  Tab:=False, Semicolon:=False, _
                  Comma:=False, Space:=False, _
                  Other:=True, OtherChar:=sDelimiter
            End With
            x = x + 1
        Wend
    
    ExitHandler:
        Application.ScreenUpdating = True
        Set wkbAll = Nothing
        Set wkbTemp = Nothing
        Exit Sub
    
    ErrHandler:
        MsgBox Err.Description
        Resume ExitHandler
    End Sub
    =====================================

    ===[Input file: A1]====Note: 2 lines of sample data=========

    PROPERTYID|CLIENTCERTIFICATEDIR|AUTHENTICATIONTYPES|AUTHENTICATIONDELAY|CHAPCHALLENGESIZE|AUTHMECHANISMS|SIGNINGALGORITHMS|CIPHERMETHODS|SIGNINGMETHODS|AUDITDELAY|AUDITTIMEOUTTIME|SERVICETOKENLIFETIME|PARLAYHEARTBEATINTERVAL|ASYNCHRONOUSTIMEOUT|HEARTBEATTIMEOUTDELAY|POLICYENABLED|HONORSERVICEAGREEMENT|DEFAULTREGISTRATIONPOLICY|DEFAULTDISCOVERYPOLICY|DEFAULTHEARTBEATPOLICY|MINIMUMHEARTBEATINTERVAL|ENFORCESELECTSERVICEAGMT|CDBRECOVERYINDICATOR
    Framework|/cust_use/FW/cert|P_AUTHENTICATION,P_OSA_AUTHENTICATION|1000|16|P_OSA_MD5|SP_NULL_STRING|SP_NULL_STRING|SP_NULL_STRING,P_MD5_RSA_1024,P_MD5_RSA_512|16000|0|60000|10000|3000|2000|N|N|IGNORE|IGNORE|IGNORE|5|N|1
    ===[End of Input file: A1 =========

    ===[Input file B1] 4 lines of sample data =========
    SERVICE_NAME|SERVICE_TYPE|ATTR_TYPE|ATTR_LIST
    SMS|2|Subscriber|SDCSACCOUNTSTATUS@SDCSMSISDN@SDCSCUSTOMERTYPE@SDCSBLACKLIST@SDCSBLACKLISTALL
    SMS|2|Enterprise|ID@NAME@TESTLIST
    SMS|2|Additional|X-CHARGEPRICE@X-BILLINGNAME
    SMS|2|Application|ID@STARTDATE@ENDDATE@STATUS@SUBSCRIBERTYPE@TESTLIST@CHARGEPRICE@APPTYPE@SHORTCODE@SUBSCRIBERIDS
    ===[end of Input file B1] =========
    Last edited by samart103; 05-06-2010 at 03:50 PM. Reason: Added Code Tags

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