+ Reply to Thread
Results 1 to 6 of 6

ActiveX Textbox copy to cell & carraige returns cause garbage character

Hybrid View

  1. #1
    Registered User
    Join Date
    11-22-2011
    Location
    New England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Question ActiveX Textbox copy to cell & carraige returns cause garbage character

    I am getting some weird behavior when I run my macro to copy the text out of an ActiveX textbox to a cell (not userform textbox). I am getting an extra symbol for male character after most (but not all??) of my carriage returns. It looks like this:

    Recent Events
    --blah blah blah
    --More blah
    --blah

    Upcoming Events
    --Soon blah blah blah
    --other blah
    --blah

    When it copies into the cell, it looks like this:

    Recent Events(symbol for male)--blah blah blah
    --More blah
    --blah (symbol for male)(symbol for male)Upcoming Events(symbol for male)--Soon blah blah blah(symbol for male)--other blah(symbol for male)--blah

    Why is this happening? Is this a bug?

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: ActiveX Textbox copy to cell & carraige returns cause garbage character

    It's because vbCr are ignored in cells and displayed as unknown characters, new lines in cells use vbLf, so you need to replace vbCr with vbLf

    Cells(1, 1).Value = Replace(Me.TextBox1.Text, Chr(13), vbLf)

  3. #3
    Registered User
    Join Date
    11-22-2011
    Location
    New England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: ActiveX Textbox copy to cell & carraige returns cause garbage character

    Quote Originally Posted by Kyle123 View Post
    It's because vbCr are ignored in cells and displayed as unknown characters, new lines in cells use vbLf, so you need to replace vbCr with vbLf

    Cells(1, 1).Value = Replace(Me.TextBox1.Text, Chr(13), vbLf)
    But it is an ActiveX Textbox, so my code currently looks like this:
    Cells(1, 1) = Sheets("MySheet").Shapes("TextBox 1").TextFrame.Characters.Text
    How do I do this with an ActiveX textbox?

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: ActiveX Textbox copy to cell & carraige returns cause garbage character

    That isn't an ActiveX textbox, it's a normal textbox - my post was for an ActiveX textbox.

    A normal textbox would be like this:

    Cells(1, 1) = Replace(Sheets("MySheet").TextBoxes("Text Box 1").Text, vbCr, vbLf)
    Hope that helps
    Last edited by Kyle123; 12-08-2011 at 09:08 AM. Reason: shortened code

  5. #5
    Registered User
    Join Date
    11-22-2011
    Location
    New England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: ActiveX Textbox copy to cell & carraige returns cause garbage character

    Thanks. I think that did it.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: ActiveX Textbox copy to cell & carraige returns cause garbage character

    Great, please mark your thread as solved

+ 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