+ Reply to Thread
Results 1 to 11 of 11

Odd behaviour in CRLF Code using cells with multi-line text

  1. #1
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Odd behaviour in CRLF Code using cells with multi-line text

    I have a minor annoyance when I create text files using a macro.

    I am using normal code to open text files, then using 'Print' to write the data.

    What happens is when the cell contains text that uses "Shift-Enter" to get multiple lines of text within a cell. When I print that cell, the lines of text end with vbLF. The 'print' itself ends with vbCRLF.

    During my 'print', how can I make every line always end with vbCRLF?

    Currently, I'm using NotePad++ to "fix" the file. I open the file, do Ctrl-A, Ctrl-X, Ctrl-V, Ctrl-S, Ctrl-W. Open the next file. Doesn't sound like a big deal, but doing 100 or more files this manual way seems silly.

    I'd love to know how to make the 'Print' command just do the vbCRLF even for text it's printing that only had vbLF to begin with.

    I hope this isn't a really stoopid question.
    Last edited by Rhudi; 04-19-2013 at 03:35 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    Replace vbCrLf with Chr(143), then replace vbLf with vbCrLf, then replace Chr(143) with vbCrLf, then print.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    Within the cell of multi-line text?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    Applied to the string that's in the cell before you write it to the file.

  5. #5
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    I wrote a short test. I did something wrong. I tried it a few different ways, leaving in the commented lines in and out, then picking one cell to single step through. The text on the screen in excel gets these little boxes on every line. However, the 'Print' command still leaves me with output that has vbLF on each of the multiple lines from the source text. It's almost as if the 'Print' command itself writes out the vbLF.
    Please Login or Register  to view this content.
    So, my test is to type into a cell of text, using Alt-Enter to make multiple lines in the cell. Then Open a file for output and 'Print' to that file. The output has vbLF. If I force the 'Replace$' using the code, I can make the cell get these little boxes, that do not affect the 'Print' output in any way.

    However, if I copy the cell and paste it into Notepad++, I do get CRLF on every line.
    Last edited by Rhudi; 04-19-2013 at 11:01 AM.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    I've lost the bubble. I thought you were outputting to a file -- there is nothing to do that in your code.

  7. #7
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    I am using 'Print' to put my data into a text file. I was just trying to show the steps I've been doing. The code listed was to try to do to a cell what you said, then use my other code to write the file, using that updated cell. It appears that the actual 'Print #1, Range("A1") & vbCrLf' does not care what each line has at the end. the text file I get, just has LF on the lines from the cell, and the extra vbCrLf appears as such in the text.
    Last edited by Rhudi; 04-19-2013 at 12:57 PM.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    This does exactly what I would expect:

    Please Login or Register  to view this content.
    In what way is it different that what you expect?
    Last edited by shg; 04-19-2013 at 01:36 PM.

  9. #9
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    Well, obviously when someone with real brains does it the correct way, compared to my semi-intelligent attempts, you get real results.
    Doing it your way, fixes it.
    I used to do this:
    Please Login or Register  to view this content.
    From your excellent help, this works:
    Please Login or Register  to view this content.
    I have to use .Range, instead of .Cell - I'm sure you can explain why.
    Now, I do it this way:
    Please Login or Register  to view this content.
    But, you're smarter than me. Thank you.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    Range("P" & R).Value is the same as Cells(R, "P")

  11. #11
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Re: Odd behaviour in CRLF Code using cells with multi-line text

    Oh! See what I mean about real brains vs mine?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1