ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Double quote delimiter script (https://www.excelbanter.com/excel-worksheet-functions/145950-double-quote-delimiter-script.html)

Mr BT[_2_]

Double quote delimiter script
 
Someone wrote this script for my project a few years ago. I hadn't needed it
up until now.
I am not sure if someone here in the ng wrote it or a colleague at work.
It should be adding a double quotation delimiter in every field in the excel
or csv file up to the last occupied field.
But I must be missing something because its not working for me.
Some fields will be blank even with the delimiters but that shouldn't matter
here.
Would one of you be able to tell me what isn't right about the following
script?

Thanks in advance,
MrBT

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 4/17/2005 by sbeattie
'

'
Public Sub OutputQuotedCSV()
Const QSTR As String = """"
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "File1.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, 256).End(xlToLeft))
sOut = sOut & "," & QSTR & _
Replace(myField.Text, QSTR, QSTR & QSTR) & QSTR
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub




All times are GMT +1. The time now is 01:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com