vegasbaby207
Board Regular
- Joined
- Nov 13, 2008
- Messages
- 53
Hi,
I have a relatively simply bit of code that writes 2 columns of data into a text file for importing into another system (NetSuite).
The first column is the item name, a 10 character string.
The second column is the "web copy" - the description the product that eventually flows through to our B2C website. This field has all sorts of characters, meaning that I need the file created and saved as UTF-8 format.
I am using the ADODB.Stream object and the following commands
To write the Header:
And then I look through all subsequent non-blank rows to write the lines:
The file saves correctly, and to the naked eye looks perfect.
However it does not import into NetSuite, reporting an error of a mismatch of columns.
I investigated further by trying to open the file in Excel. Bizarrely (to me), it does not recognise the double-quotations and any commas contained within the second column are separating into different excel columns.
I'm happy to upload a copy of the CSV file if that would be beneficial to anyone.
Below is a full copy of the VBA sub.
I have a relatively simply bit of code that writes 2 columns of data into a text file for importing into another system (NetSuite).
The first column is the item name, a 10 character string.
The second column is the "web copy" - the description the product that eventually flows through to our B2C website. This field has all sorts of characters, meaning that I need the file created and saved as UTF-8 format.
I am using the ADODB.Stream object and the following commands
To write the Header:
VBA Code:
fsT.WriteText ActiveCell.Value & ", " & ActiveCell.Offset(0, 160) & vbCrLf
VBA Code:
fsT.WriteText ActiveCell.Value & ", " & Chr(34) & ActiveCell.Offset(0, 160) & Chr(34) & vbCrLf
The file saves correctly, and to the naked eye looks perfect.
However it does not import into NetSuite, reporting an error of a mismatch of columns.
I investigated further by trying to open the file in Excel. Bizarrely (to me), it does not recognise the double-quotations and any commas contained within the second column are separating into different excel columns.
I'm happy to upload a copy of the CSV file if that would be beneficial to anyone.
Below is a full copy of the VBA sub.
VBA Code:
Private Sub btnSaveWeb_Click()
Dim fsT As Object
Dim sFileName As String
sFileName = "G:\TEMP\ItemUploads\Web Copy - " & Format(Date, "yyyy-mm-dd") & ".csv"
Set fsT = CreateObject("ADODB.Stream")
fsT.Type = 2
fsT.Charset = "utf-8"
fsT.Open
Range("A1").Activate
fsT.WriteText ActiveCell.Value & ", " & ActiveCell.Offset(0, 160) & vbCrLf
ActiveCell.Offset(1, 0).Activate
While ActiveCell.Value <> ""
fsT.WriteText ActiveCell.Value & ", " & Chr(34) & ActiveCell.Offset(0, 160) & Chr(34) & vbCrLf
ActiveCell.Offset(1, 0).Activate
Wend
fsT.SaveToFile sFileName, 2
End Sub