How to remove extra carriage return - Word

Answered How to remove extra carriage return - Word

  • Monday, January 17, 2011 10:32 AM
     
     

    Hi,

    Redirected from Visual C# forum, sry for double post...

    Im using C# and word API to copy the content of one document onto another with template to apply the macros. However when pasting a extra carriage return is added and i've been trying some solutions found on this forum but none worked.

    A simple solution: How can i move the cursor to the end of the document and then use backspace?

    Thanks

All Replies

  • Monday, January 17, 2011 10:10 AM
     
     

    Hi,

    Im using C# and word API to copy the content of one document onto another with template to apply the macros. However when pasting a extra carriage return is added and i've been trying some solutions found on this forum but none worked.

    A simple solution: How can i move the cursor to the end of the document and then use backspace?

    Thanks

    • Moved by Leo Liu - MSFT Wednesday, January 19, 2011 9:44 AM Off-topic, moved for better support. (From:Visual C# General)
    • Merged by Bruce SongModerator Thursday, January 20, 2011 6:22 AM duplicated
    •  
  • Monday, January 17, 2011 10:25 AM
     
     

    Welcome to MSDN Forums.

    However you may got an answer here but also try Word For Developers Forum where you'll find more related experts.

    Sincerely,

    Yasser.


    LEARN HOW TO USE WINDOWS API DURING A QUICK, SIMPLE AND PRACTICAL HOW TO:
    How To: Changing TextBox blinking caret using Windows API
  • Monday, January 17, 2011 2:40 PM
    Moderator
     
     Answered

    Hi just_rice

    I'm not sure that your proposed approach is the best one, but that's hard to say without more information... Most likely, this extra carriage return is the combination of the last paragraph mark in the target document and the last paragraph mark in the source document. Deleting the one or the other could change critical formatting, so before deciding which one to remove you need to determine whether the section formatting in the one or the other is most important.

    This is best done testing as an end-user. Open both documents in Word. In the source document, test the following two scenarios:

    1. Ctrl+A (select all), Ctrl+C, switch to the target document and paste (Ctrl+V), then press Del.

    2. Ctrl+A, Shift+Left Arrow (this cuts off the last paragraph mark), Ctrl+C, switch to the target document and paste.

    Which of these two approaches gives you the better result?


    Cindy Meister, VSTO/Word MVP
  • Monday, January 17, 2011 2:46 PM
     
     

    Well the reason for this copy paste is that the macros in template are password protected which I can't do through just C# code (except using sendkeys which i prefer not to use).

    Thanks for your answers but I'm doing this in C# so do you know the methods to make your operations? It is as you say that when copying I get the extra last paragraph mark.

  • Monday, January 17, 2011 3:01 PM
    Moderator
     
     

    Hi just_rice

    You first need to decide which paragraph mark you should be deleting, which is why I wrote out those two sets of steps. The code you need depends on which paragraph mark you prefer to keep.


    Cindy Meister, VSTO/Word MVP