A family of Microsoft relational database management systems designed for ease of use.
Okay, here's a quick & dirty example procedure:
'------ start of code ------
Sub CopyAndModifyCSV()
On Error GoTo Err_Handler
Dim strInputFile As String
Dim strOutputFile As String
Dim strBackupFile As String
Dim strLine As String
Dim intFileIn As Integer
Dim intFileOut As Integer
Dim astrData() As String
strInputFile = "C:\My Path\To\MyFile.csv"
strOutputFile = CurrentProject.Path & "\TempCSVCopy.csv"
' Open the input and output files
intFileIn = FreeFile()
Open strInputFile For Input As #intFileIn
intFileOut = FreeFile()
Open strOutputFile For Input As #intFileOut
' Read and copy header line.
Line Input #intFileIn, strLine
Print #intFileOut, strLine
' Read and fix the first data line.
Line Input #intFileIn, strLine
astrData = Split(strLine, ",")
If UBound(astrData) <> 4 Then
Err.Raise vbObjectError + 1, , "Data line does not have the expected number of columns."
End If
astrData(4) = "Whatever you want it to be"
strLine = Join(astrData, ",")
Print #intFileOut, strLine
' Read and copy all the remaining lines.
Do Until EOF(intFileIn)
Line Input #intFileIn, strLine
Print #intFileOut, strLine
Loop
' Rename the original file to ".bak", and rename the output file
' to the original file name.
strBackupFile = strInputFile & ".bak"
If Len(Dir(strBackupFile)) <> 0 Then
Kill strBackupFile
End If
Name strInputFile As strBackupFile
Name strOutputFile As strInputFile
Exit_Point:
Close
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_Point
End Sub
'------ end of code ------
Note that this won't work if any of the data elements in the row to be changed contains a comma. That's because the code uses the Split function to break the line up into separate columns, using the comma as a delimiter. It won't know if one column's data was a quoted string containing a comma. It also won't work if the second row (the first data row) doesn't have all 5 elements. But the code could be modified to be more sophisticated, if necessary.