none
Delete last character in cell RRS feed

  • Question

  • I have a VB.NET app which manipulates word documents.

    There is a table in the document and in certain cells I have to insert a RTF file. This works fine.

    But after the RTF file is inserted Word seems to add a line break at the end.

    I'm trying to delete this line break but have no luck.

    I have tried this code: r is a range object, the content of the cell where the rtf file was inserted

    r.Word.Item(r.Words.Count-1)  'Get last Word in cell
    r.Select  'Select the word
    Wordapp.Selection.Typebackspace  'and _enter_ a backspace

    This basically does what I want but if the last line/paragraph has bullets, the bullet on the last line is removed.

    Thomas

    Thursday, January 3, 2013 9:17 AM

Answers

  • Hi Thomas,

    Thanks for posting in the MSDN Forum.

    I think you need use Application.Selection.MoveUp / MoveDown / MoveLeft / MoveRight to move cursor to right position then use Application.Selection.TypeBackspace to approach your goal.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 7, 2013 4:26 AM
    Moderator
  • I had to select the last word in the range, MoveRight one character and then TypeBackspace to get it to work.

    Thanks for your help.

    Monday, January 7, 2013 8:52 AM

All replies

  • Hi THomas

    What happens if you use Delete instead of backspace?

    The problem you're seeing is due to "bullets" being a paragraph-level formatting. If you delete the paragraph mark, you delete the paragraph-level formatting, but sometimes it behaves differently with delete as opposed to backspace...


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, January 3, 2013 10:22 AM
    Moderator
  • I tried this but Word still deletes the bullets on the last line.

    Thomas

    Thursday, January 3, 2013 10:44 AM
  • Hi Thomas,

    Thanks for posting in the MSDN Forum.

    I think you need use Application.Selection.MoveUp / MoveDown / MoveLeft / MoveRight to move cursor to right position then use Application.Selection.TypeBackspace to approach your goal.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 7, 2013 4:26 AM
    Moderator
  • I had to select the last word in the range, MoveRight one character and then TypeBackspace to get it to work.

    Thanks for your help.

    Monday, January 7, 2013 8:52 AM