Double quote delimiter script

M

Mr BT

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top