I am trying to figure out how to do the following, hoping someone can assist. Thanks in advance
1.How to set default formatting - I think I have this
2. Save as CSV - I think I have this
3. Save as UTF-8 I think I have this
4. set Field del = "," and txt del = " - Here I would need help
5. Quote all text cells - help
6. Save cell content as show - help
1.How to set default formatting - I think I have this
2. Save as CSV - I think I have this
3. Save as UTF-8 I think I have this
4. set Field del = "," and txt del = " - Here I would need help
5. Quote all text cells - help
6. Save cell content as show - help
Code:
[/B]Sub OTimport()
<code>ThisWorkbook.ActiveSheet.Cells.ClearFormats
Set wkb = ActiveSheet
Dim fileName As String
Dim MaxCols As Integer
fileName = Application.GetSaveAsFilename("C:\Users\ADMIN\Desktop\Report work\OTIMPORT" & Format(Now(), "DD-MMM-YYYY hh mm AMPM"), "CSV File (*.csv), *.csv")
If fileName = "False" Then
End
End If
On Error GoTo eh
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Charset = "UTF-8"
BinaryStream.Type = adTypeText
BinaryStream.Open
For r = 1 To 10
s = ""
C = 1
While Not IsEmpty(wkb.Cells(r, C).Value)
s = s & wkb.Cells(r, C).Value & ","
C = C + 1
Wend
BinaryStream.WriteText s, 1
Next r
BinaryStream.SaveToFile fileName, adSaveCreateOverWrite
BinaryStream.Close
MsgBox "CSV generated successfully"
eh:
</code>End Sub
[B]