Saving a Text

  • Thread starter Michael Burkett
  • Start date
M

Michael Burkett

I am trying to save a list of values across several rows as a text file with a single space in between each value. When I open the file in notepad Space Delimited just crams all of the values together and Tab Delimited puts more than 1 space. Anyone know of a way to save with just a single space in between?
 
G

GS

I am trying to save a list of values across several rows as a text
file with a single space in between each value. When I open the file
in notepad Space Delimited just crams all of the values together and
Tab Delimited puts more than 1 space. Anyone know of a way to save
with just a single space in between?

In a standard module...

Option Explicit

Sub CSVtoText()
Dim vDataIn, n&, j&, sDataOut$
vDataIn = ActiveSheet.UsedRange
For n = LBound(vDataIn) To UBound(vDataIn)
For j = LBound(vDataIn) To UBound(vDataIn, 2)
sDataOut = sDataOut & vDataIn(n, j)
If Not j = UBound(vDataIn, 2) Then sDataOut = sDataOut & " "
Next 'j
If Not n = UBound(vDataIn) Then sDataOut = sDataOut & vbCrLf
Next 'n
WriteTextFileContents sDataOut, "C:\test_CSVtoText.txt"
End Sub

Sub WriteTextFileContents(TextOut$, Filename$, _
Optional AppendMode As Boolean = False)
' Reusable procedure that Writes/Overwrites or Appends
' large amounts of data to a Text file in one single step.
' **Does not create a blank line at the end of the file**
Dim iNum As Integer
On Error GoTo ErrHandler
iNum = FreeFile()
If AppendMode Then
Open Filename For Append As #iNum: Print #iNum, vbCrLf & TextOut;
Else
Open Filename For Output As #iNum: Print #iNum, TextOut;
End If

ErrHandler:
Close #iNum: If Err Then Err.Raise Err.Number, , Err.Description
End Sub 'WriteTextFileContents()

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
M

Michael Burkett

Thank you Garry. I will give this a shot.

In a standard module...



Option Explicit



Sub CSVtoText()

Dim vDataIn, n&, j&, sDataOut$

vDataIn = ActiveSheet.UsedRange

For n = LBound(vDataIn) To UBound(vDataIn)

For j = LBound(vDataIn) To UBound(vDataIn, 2)

sDataOut = sDataOut & vDataIn(n, j)

If Not j = UBound(vDataIn, 2) Then sDataOut = sDataOut & " "

Next 'j

If Not n = UBound(vDataIn) Then sDataOut = sDataOut & vbCrLf

Next 'n

WriteTextFileContents sDataOut, "C:\test_CSVtoText.txt"

End Sub



Sub WriteTextFileContents(TextOut$, Filename$, _

Optional AppendMode As Boolean = False)

' Reusable procedure that Writes/Overwrites or Appends

' large amounts of data to a Text file in one single step.

' **Does not create a blank line at the end of the file**

Dim iNum As Integer

On Error GoTo ErrHandler

iNum = FreeFile()

If AppendMode Then

Open Filename For Append As #iNum: Print #iNum, vbCrLf & TextOut;

Else

Open Filename For Output As #iNum: Print #iNum, TextOut;

End If



ErrHandler:

Close #iNum: If Err Then Err.Raise Err.Number, , Err.Description

End Sub 'WriteTextFileContents()



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion







---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com
 

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