vbCr being ignored

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi there,

Can anyone help me with a weird string problem? Basically the vbCr, in the
middle of the code snippet below, seems to be ignored when you add the text
at the end to a text file, but appears to work ok when using Debug.Print.
Is there something about the text conversion process that ignores carriage
returns?

Many thanks

John

For Each myRun In shp.TextFrame.TextRange.Runs
If myRun.Font.Name = "Arial" Then
hdrsCol.Add (myRun)
..........................
For Each myRun In hdrsCol
sContentsText = sContentsText & vbCr & CStr(myRun)
Debug.Print sContentsText
Next myRun
..........................
'Open new text file and add text
FileNum = FreeFile
Open sTextFileName For Output As FileNum
Print #FileNum, sContentsText
Close FileNum

..........................
 
Hi there,

Can anyone help me with a weird string problem? Basically the vbCr, in the
middle of the code snippet below, seems to be ignored when you add the text
at the end to a text file, but appears to work ok when using Debug.Print.
Is there something about the text conversion process that ignores carriage
returns?

DOS/Windows uses CR + LF as a linebreak character rather than CR or LF alone.

Use VBCrLf instead of VBCr

If you need to maintain the solo-CRs in your text ranges you could leave that
part of the code alone but do this to write to file:

Print #FileNum, Replace(sContentsText,vbCr,vbCrLf)

I think that should do it.
 
Hi Steve,

That's perfect. Thanks very much for your help.

Best regards

John
 

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

Back
Top