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

ImportFromCSV

Imports a CSV/TSV file’s content to the current instance.


Syntax

expression.ImportFromCSV(configObj, [FilterColumns])

Parameters

Part Description
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 ImportFromCSV method returns a non-initialized object.

☕Example

Sub ImportFromCSV()
    Dim CSVint As CSVinterface
    
    Set CSVint = New CSVinterface
    With CSVint.parseConfig
        .path = Environ("USERPROFILE") & "\Desktop\Demo_100000records.csv"
        Set .dialect = CSVint.SniffDelimiters(CSVint.parseConfig)               'Sniff delimiters and save the result in the config object
    End With
    With CSVint
        .ImportFromCSV .parseConfig                                             'Import CSV data
    End With
    Set CSVint = Nothing
End Sub

Back to Methods overview