+ Reply to Thread
Results 1 to 10 of 10

How to put CR/LF into a string?

  1. #1
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    How to put CR/LF into a string?

    Hi!

    Consider you have 3 strings
    Please Login or Register  to view this content.
    then you like to do something like this

    Please Login or Register  to view this content.
    and then you would like to paste it to Notepad so there would be two lines.
    Chr(13) does not work, neither does vbCRLf work...

    What should be instead of Chr(13), so when you paste both to Notepad there
    would then be two lines? Like this:
    abc - this would be the first line
    def - and this would be se second line

    as the attachment TwoLines.txt

    regards
    keymuu
    Last edited by keymuu; 11-20-2012 at 08:39 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,549

    Re: How to put CR/LF into a string?

    This works for me:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to put CR/LF into a string?

    Hi RMS!

    That should work, mainly because all happens inside Excel.
    However, when my data (two lines) will end up in Notepad
    just one road with vbCrLf in the middle of those two strings
    "Your code" will of course run perfectly in every pc-computer
    equipped with Excel. But when I take two strings and try
    to combine them to a third one will find in Notepad just one
    row with Str1 vbCrLf (as text) and Str2, in one line.

    One would expect some other approach, but unfortunately I'm
    not aware of such a thing so I thought that I could find some
    help here in this forum.

    regards
    keymuu

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,549

    Re: How to put CR/LF into a string?

    I'm not really sure what you are asking. This is an Excel programming sub forum and you have quoted Excel VBA code. My code works in that it will create a string over two lines using CRLF ... and, if I copy and paste it into Notepad, it still has two lines.

    If I just select the cell and copy it:

    HTML Code: 

    If I edit the cell and select all the text in the formula bar:

    HTML Code: 

    Where and how are you creating your two "rows" and where and how are you trying to combine them?


    Regards, TMS

  5. #5
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to put CR/LF into a string?

    Hi TMS,

    I'm creating things in Excel and I need to be absolutely sure I paste them correctly to IE,
    so, after the data is pasted to IE I select all there and copy it back and check if it is
    correctly written there. Unfortunately it is not always correct written there (maybe 0,5%).
    I try get that failure percent smaller and thats is why try to create a log file. However I have
    not found a way how to create new lines in Notepad. Without finding a way to "hit Enter" in
    the strings will all strings in one single line with a vbCrLf between the strings, even that all
    should be in their own lines. Here is line where I collect it
    clipboardData = Now & vbTab & Here & vbCrLf & There & vbCrLf

    And a surrounding of it is like this a clip of this is like this,
    Here and There are those strings that are collected together:
    Please Login or Register  to view this content.
    This should answer where and how I creating those two lines now and how I combine them

    regards
    keymuu

  6. #6
    Registered User
    Join Date
    11-16-2012
    Location
    Crownpoint, New Mexico
    MS-Off Ver
    All.
    Posts
    59

    Re: How to put CR/LF into a string?

    vbcrlf
    is
    chr(13) & chr(10)

    Regards...

    so

    Please Login or Register  to view this content.
    Please click * to add to my reputation!

  7. #7
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to put CR/LF into a string?

    Hi !

    Is life strange?
    One could really say life is not strange at all compared with Windows.

    I got it to work by adding a delay (0,5sec) between Call Notepad and pasteIt.
    Without the delay it did not work, maybe one time of 20 or so, but 19 times
    it was just one line with a written vbCrLf between those to strings, strange indeed.
    So one can one time say "Welcome to the Windows world!". One does not have
    a clue what is happening in the scenes behind in the computer in front of you,
    and could continue saying "Thank you Microsoft!"....

    regards
    keymuu

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,549

    Re: How to put CR/LF into a string?

    I'm glad you got it to work.

    It would be useful if you shared your solution for the benefit of others. I'm sure that a sample workbook with all the relevant code would be very interesting to the group.

    Regards, TMS


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  9. #9
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to put CR/LF into a string?

    Hi again!

    As I said a pause before paste did the trick,

    it looks like this now:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    regards
    keymuu

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,549

    Re: How to put CR/LF into a string?

    Thank you. I'm sure there will be people who will find this technique useful.


    Regards, TMS

+ 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