Find Result Copy And Paste

Discussion in 'Word Programming' started by jic, Jan 27, 2012.

  1. jic

    jic Guest

    Hi.

    I am doing a search on two documents for highlighted words or
    sentences. The both finds commands are working find, but the copy and
    paste are adding an extra newline.

    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, 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
     
    jic, Jan 27, 2012
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. kph
    Replies:
    0
    Views:
    134
  2. prasanta

    Copy and paste events

    prasanta, Aug 13, 2005, in forum: Word Programming
    Replies:
    0
    Views:
    135
    prasanta
    Aug 13, 2005
  3. delphis96 via OfficeKB.com

    Copy Paste from IE to Word(2003), re-style text, maintain formatting

    delphis96 via OfficeKB.com, Oct 12, 2006, in forum: Word Programming
    Replies:
    4
    Views:
    256
    delphis96 via OfficeKB.com
    Oct 19, 2006
  4. Supriya

    How to copy row and paste

    Supriya, May 22, 2007, in forum: Word Programming
    Replies:
    2
    Views:
    132
    digbydog
    May 30, 2007
  5. OTWarrior via OfficeKB.com

    import text from another document, paste into form field result

    OTWarrior via OfficeKB.com, Sep 18, 2007, in forum: Word Programming
    Replies:
    6
    Views:
    93
    fumei via OfficeKB.com
    Sep 24, 2007
  6. jason
    Replies:
    10
    Views:
    183
    Lene Fredborg
    Oct 5, 2009
  7. John
    Replies:
    5
    Views:
    231
    Doug Robbins - Word MVP
    Mar 26, 2010
  8. JD
    Replies:
    0
    Views:
    408
Loading...