InsertField
Inserts a new field, at the specified position, in the imported CSV data.
Syntax
expression.InsertField
(aIndex, [FieldName])
Parameters
Part | Description |
---|---|
aIndex | Required. Identifier specifying a Long Type variable. Represents the index in which the new field will be inserted. |
FieldName | Optional. Identifier specifying a String Type variable representing the name of the new field. |
Formula | Optional. Identifier specifying a String Type variable representing the expression used to compute the value for the new field. |
Returns value
Type: CSVinterface
- See also
- ImportFromCSV method, ImportFromCSVstring method.
Behavior
The InsertField
method will insert a new field into all records, if they all have the same number of fields, in the current instance. The value of the FieldName
parameter will be inserted into the record/first row, otherwise not. If a formula is given, the field is populated in each record (row) with the result of evaluating the formula on each field.
☕Example
Sub InsertField()
Dim CSVint As CSVinterface
Set CSVint = New CSVinterface
With CSVint.parseConfig
.path = Environ("USERPROFILE") & "\Desktop\Chinese CSV.csv"
.utf8EncodedFile = True 'The file is UTF-8 encoded
End With
With CSVint
.ImportFromCSV .parseConfig
.InsertField .fieldsBound + 1, "Taxes" , "FORMAT(Total Revenue * Percent(18);'Currency')") 'Insert a field named "Taxes"
'and use a custom fomula for compute it.
End With
Set CSVint = Nothing
End Sub