Results 1 to 5 of 5

Thread: Solved: Text formatting

  1. #1

    Solved: Text formatting

    Hello,

    I am copying a text from Word to a VB text box. I want to clean the format of the text from numbering and bullets before I pass it to the control in VB.


    I am using the clipboard object to get the text.

    Worddoc.Application.Selection.Copy()

    Thank you in advance for your help

    Joey

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    You'll need to assign the text to a string variable first so you can do stuff with it.
    If you're selection has bulleted or numbered styles, then the text property shouldn't be carrying those over. You will have to strip off paragraph mark at the end tho.[VBA]Dim strText As String

    strText = Application.Selection.Text

    'get rid of paramark
    If Right(strText, 1) = Chr(13) Then strText = Left(strText, Len(strText) - 1)
    'remove leading and trailing spaces
    strText = Trim(strText)

    TextBox1.Text = strText[/VBA]
    K :-)

  3. #3
    VBAX Expert
    Joined
    Feb 2005
    Posts
    924
    Location
    Quote Originally Posted by Killian
    You'll need to assign the text to a string variable first so you can do stuff with it.
    If you're selection has bulleted or numbered styles, then the text property shouldn't be carrying those over. You will have to strip off paragraph mark at the end tho.[VBA]Dim strText As String

    strText = Application.Selection.Text

    'get rid of paramark
    If Right(strText, 1) = Chr(13) Then strText = Left(strText, Len(strText) - 1)
    'remove trailing spaces
    strText = Trim(strText)

    TextBox1.Text = strText[/VBA]
    A small point: the Trim function will remove both leading and trailing spaces. LTrim and RTrim will remove just leading and trailing respectively. In the above case, I suspect that the removal of both leading and trailing is appropriate.

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Quite right. Which is what I did... I've edited my code comment appropriately
    K :-)

  5. #5
    Thanks guys. It worked just fine.

Posting Permissions

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