Skip to main content Link Search Menu Expand Document (external link) Copy Copied

ImportFromCSVstring

Parses a string and save its CSV/TSV data to the current instance.


Syntax

expression.ImportFromCSVstring(CSVstring, configObj, [FilterColumns])

Parameters

Part Description
CSVstring Required. Identifier specifying a String Type variable representing the data to be parsed.
configObj Required. Identifier specifying a CSVparserConfig object variable.
FilterColumns Optional. Identifier specifying a ParamArray of Variant Type variable.

Returns value

Type: CSVinterface

See also
ParseConfig Property, CSVTextStream class.

Behavior

The configObj parameter is an object with all the options considered by the parser during the import operation, see the ParseConfig Property documentation. User can use the FilterColumns parameter for retrieve only certain fields from each CSV/TSV record. The filters can be strings representing the names of the fields determined with the header record, or numbers representing the position of the requested field. If not filters defined, all the fields of the requested records will be retrieved.

⚠️Caution

If the target file has no data (the file is an empty one) or an error occur when parsing, the ImportFromCSVstring method returns a non-initialized object.

☕Example

Sub ImportFromString()
    Dim CSVint As CSVinterface
    Dim CSVdata As String
    Dim fPath As String
    
    Set CSVint = New CSVinterface
    fPath = Environ("USERPROFILE") & "\Desktop\Demo_100000records.csv"
    With CSVint
        CSVdata = .GetDataFromCSV(fPath)
        Set .parseConfig.dialect = .SniffDelimiters(.parseConfig, CSVdata)      'Sniff delimiters and save to config object
        .ImportFromCSVString CSVdata, .parseConfig                              'Import CSV data
    End With
    Set CSVint = Nothing
End Sub

Back to Methods overview