Next
End Function
+Function QuoteIfNeeded(str)
+ Dim fQuote
+ If InStr(str, vbTab) > 0 Then
+ fQuote = True
+ ElseIf InStr(str, """") > 0 Then
+ fQuote = True
+ ElseIf InStr(str, vbLf) > 0 Then
+ fQuote = True
+ End If
+ If fQuote Then
+ QuoteIfNeeded = """" & Replace(str, """", """""") & """"
+ Else
+ QuoteIfNeeded = str
+ End If
+End Function
+
Function writeCellValues(fo, sht)
Dim varCells, row, col, ary()
varCells = sht.UsedRange.Value
If TypeName(varCells) = "String" Then
- fo.WriteLine varCells
+ fo.WriteLine QuoteIfNeeded(varCells)
ElseIf Not IsEmpty(varCells) Then
ReDim ary(UBound(varCells, 2))
On Error Resume Next
For row = 1 To UBound(varCells, 1)
For col = 1 To UBound(varCells, 2)
- ary(col - 1) = CStr(varCells(row, col))
+ ary(col - 1) = QuoteIfNeeded(CStr(varCells(row, col)))
If Err.Number <> 0 Then
ary(col - 1) = "Error" & Err.Number
Err.Clear