Hisam
07-20-2017, 11:13 PM
I have a VBA Excel macro that loads content of 2 utf-8 files and add/save it to another utf-8 file. Part of the code is:
Sub
Set oResult = CreateObject("ADODB.Stream")
oResult.Type = 1
oResult.Open
AddFileToStream oResult, ReadBinaryFile("c:\path\file1.csv")
AddFileToStream oResult, ReadBinaryFile("c:\path\file2.csv")
' save the file
oResult.SaveToFile ("c:\merge\file.csv")
Next i
End Sub
Sub AddFileToStream(ByRef oStream, ByVal btBinary)
oStream.Position = oStream.Size
oStream.Write (btBinary)
End Sub
Function ReadBinaryFile(ByVal sFilePath)
Dim oStream
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sFilePath
ReadBinaryFile = oStream.Read
oStream.Close
Set oStream = Nothing
End Function
Problem is that, when macro merged them, the first data entry of second merging document in the merged document (utf-8 file) have these strange format characters and I cannot find the way to get rid of them. The outcome file has to be without these characters because other system doesn't work and procedure stops with error. Probably the reason why it is hapenning is because it's chucking in the file header which specifies that the file is in UTF-8 format. It loos like this:
19831
Is it possible to solve it?
Sub
Set oResult = CreateObject("ADODB.Stream")
oResult.Type = 1
oResult.Open
AddFileToStream oResult, ReadBinaryFile("c:\path\file1.csv")
AddFileToStream oResult, ReadBinaryFile("c:\path\file2.csv")
' save the file
oResult.SaveToFile ("c:\merge\file.csv")
Next i
End Sub
Sub AddFileToStream(ByRef oStream, ByVal btBinary)
oStream.Position = oStream.Size
oStream.Write (btBinary)
End Sub
Function ReadBinaryFile(ByVal sFilePath)
Dim oStream
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile sFilePath
ReadBinaryFile = oStream.Read
oStream.Close
Set oStream = Nothing
End Function
Problem is that, when macro merged them, the first data entry of second merging document in the merged document (utf-8 file) have these strange format characters and I cannot find the way to get rid of them. The outcome file has to be without these characters because other system doesn't work and procedure stops with error. Probably the reason why it is hapenning is because it's chucking in the file header which specifies that the file is in UTF-8 format. It loos like this:
19831
Is it possible to solve it?