Hello there, I created a csv file which when opened in notepad, shows the records having double quotes. How do I use VBA to read the file, replace double quotes with no quotes and write the file out by replacing the original file? By the way, I am doing this in MS Access.
All help will be appreciated.. Thanks
Comments
: shows the records having double quotes. How do I use VBA to read the
: file, replace double quotes with no quotes and write the file out by
: replacing the original file? By the way, I am doing this in MS
: Access.
:
: All help will be appreciated.. Thanks
:
try this-
[code]
Option Compare Database
Option Explicit
Sub ReplaceCharacters()
Dim arBuffer() As String
Const FileRead = "d:myfile.txt"
Const FileWrite = "d:myfile2.txt"
Dim FF1 As Integer
Dim num As Integer
Dim InputData As String
On Error GoTo erh
'READ FILE
FF1 = FreeFile
num = 0
Open FileRead For Input As #FF1
'loop thru file
Do While Not EOF(FF1)
'get a line
Line Input #FF1, InputData
num = num + 1
ReDim Preserve arBuffer(num)
'store in array
arBuffer(num) = InputData
Loop
Close #FF1
'REPLACE CHARACTER
Dim i As Integer
Dim DblQuote As String * 1
DblQuote = Chr$(34)
For i = 1 To num
arBuffer(i) = Replace(arBuffer(i), DblQuote, "")
Next i
'WRITE FILE
FF1 = FreeFile
Open FileWrite For Output As #FF1
For i = 1 To num
'write array item to file
Print #FF1, arBuffer(i)
Next i
Close #FF1
xit:
Exit Sub
erh:
MsgBox Err.Description, vbCritical, Err.Number
Resume Next
End Sub
[/code]