Originally Posted by
GTO
Hi All,
I could be off base, but I think that the csv is tacking in the extra quotes around sections that contain commas. In addition, there are quote marks designating inches.
If you are wanting to save it in .txt format, as comma delimited, maybe substitute something for the comma?
[VBA]
Option Explicit
Sub exampleExport()
Dim FSO As Object ' FileSystemObject
Dim TStream As Object ' TextStream
Dim wks As Worksheet
Dim rngLastRowCell As Range
Dim rngLastCellCol As Range
Dim aryVals As Variant
Dim x As Long
Dim y As Long
Dim strText As String
Set wks = ThisWorkbook.Worksheets("Sample")
With wks
Set rngLastCellCol = FindRange(RangeArg:=.Cells, ByColOrRow:=xlByColumns)
If rngLastCellCol Is Nothing Then Exit Sub
Set rngLastRowCell = FindRange(.Cells)
aryVals = .Range(.Cells(1), .Cells(rngLastRowCell.Row, rngLastCellCol.Column))
End With
Set FSO = CreateObject("Scripting.FileSystemObject")
Set TStream = FSO.CreateTextFile(ThisWorkbook.Path & "\Test.txt", True)
For x = 1 To UBound(aryVals, 1)
strText = vbNullString
For y = 1 To UBound(aryVals, 2)
strText = strText & Replace(aryVals(x, y), ",", ";") & ","
Next
TStream.WriteLine Left(strText, Len(strText) - 1)
Debug.Print Left(strText, Len(strText) - 1)
Next
TStream.Close
End Sub
Function FindRange(RangeArg As Range, _
Optional ByVal FindWhat As Variant = "*", _
Optional FindAfter As Range, _
Optional LookWhere As XlFindLookIn = xlValues, _
Optional WholeOrPart As XlLookAt = xlPart, _
Optional ByColOrRow As XlSearchOrder = xlByRows, _
Optional NextOrPrevious As XlSearchDirection = xlPrevious, _
Optional MatchCaseBool As Boolean = False, _
Optional MatchFound As Boolean = False) As Range
If FindAfter Is Nothing Then
Set FindAfter = RangeArg(1, 1)
End If
Set FindRange = RangeArg.Find(What:=FindWhat, _
After:=FindAfter, _
LookIn:=LookWhere, _
LookAt:=WholeOrPart, _
SearchOrder:=ByColOrRow, _
SearchDirection:=NextOrPrevious, _
MatchCase:=MatchCaseBool)
MatchFound = Not FindRange Is Nothing
End Function
[/VBA]