locked
Find Result Copy And Paste Adding Extra Newline RRS feed

  • Question

  • Hi. 

    I am doing a search on two documents for highlighted words or 
    sentences in Word 2003.  The both finds commands are working fine, but either the copy or the paste is adding an extra newline to the Pasted string. 

      var ad = word.Documents.Open(file); 
      xf = word.ActiveDocument; // Extract From doc 
      xfRange = xf.Range(0,0); 
      //xSel = word.Selection; 
      var doc = word.Documents.Open(tfile);// the translated file with 
    translated strings 
      as = word.ActiveDocument; 
      var myRange = doc.Range(0,0); 
    
      xfRange.Find.ClearFormatting(); 
      xfRange.Find.Highlight = true; 
      xfRange.Find.Replacement.ClearFormatting(); 
      xfRange.Find.Text = ""; 
      xfRange.Find.Forward = true; 
      xfRange.Find.Wrap = wdFindStop; // stop after end of document 
      xfRange.Find.Format = true; 
      xfRange.Find.MatchCase = false; 
      xfRange.Find.MatchWholeWord = false; 
      xfRange.Find.MatchKashida = false; 
      xfRange.Find.MatchDiacritics = false; 
      xfRange.Find.MatchAlefHamza = false; 
      xfRange.Find.MatchControl = false; 
      xfRange.Find.MatchByte = false; 
      xfRange.Find.CorrectHangulEndings = false; 
      xfRange.Find.MatchWildcards = false; 
      xfRange.Find.MatchSoundsLike = false; 
      xfRange.Find.MatchAllWordForms = false; 
      xfRange.Find.Execute(); 
    
      myRange.Find.ClearFormatting(); 
      myRange.Find.Highlight = true; 
      myRange.Find.Replacement.ClearFormatting(); 
      myRange.Find.Text = ""; 
      myRange.Find.Forward = true; 
      myRange.Find.Wrap = wdFindStop; // stop after end of document 
      myRange.Find.Format = true; 
      myRange.Find.MatchCase = false; 
      myRange.Find.MatchWholeWord = false; 
      myRange.Find.MatchKashida = false; 
      myRange.Find.MatchDiacritics = false; 
      myRange.Find.MatchAlefHamza = false; 
      myRange.Find.MatchControl = false; 
      myRange.Find.MatchByte = false; 
      myRange.Find.CorrectHangulEndings = false; 
      myRange.Find.MatchWildcards = false; 
      myRange.Find.MatchSoundsLike = false; 
      myRange.Find.MatchAllWordForms = false; 
      myRange.Find.Execute(); 
      while (myRange.Find.Found == true) 
      { 
        if (myRange.Find.Parent.HighlightColorIndex == wdYellow) 
        { 
          if (xfRange.Find.Found == true) 
          { 
    
            xfRange.Find.Parent.Copy(); 
            myRange.Find.Parent.Paste(); 
    
            xfRange.Find.Execute(); 
          } 
          else 
          { 
            w.Echo("Oh boy!  Problem on the land..."); 
            w.Quit(); 
          } 
        } 
        myRange.Find.Execute(); 
      } 
    ... 
    ....
    

     This works like a charm with the exception that the Pasted string has a newline and it breaks the sentence.  For example, say the original sentence is, 

    Hi there.  I am here and you are there. 

    Let's say that here is highlighted, after the paste, the sentence becomes, 

    Hi there. I am here 
    and you are there. 

    I am using the same document as a test.  Any help would be greatly appreciated. 

    thanks, 

    jic 

    Friday, January 27, 2012 4:55 PM

Answers

  •  

    Guys, my apologies. This works ok.  Long story short... I was extracting every yellow highlighted string from a word doc and placing it in another word doc for translation.  After translation, I would grab those and replace the translated strings in the original document.  But, when I extracted the original highlighted string, I was adding a newline to the end of that paste and when I was bringing it back, the newline came with it.  The work around is to export it to a table and just add a new cell instead of adding a newline.

     

    just fyi.

     

    thanks,

     

    josé 

    • Marked as answer by Max Meng Monday, January 30, 2012 1:08 AM
    Friday, January 27, 2012 7:29 PM