SHARE
TWEET

Untitled

a guest Jul 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private bool ReplaceText(string textToInsert)
  2.     {
  3.         bool retval = false;
  4.  
  5.         Microsoft.Office.Interop.Word.Selection currentSelection = Globals.ThisAddIn.Application.Selection;
  6.  
  7.         // if (currentSelection.ContainsTrailingParagraphMark)
  8.         // {
  9.         //    retval = true;
  10.         // }
  11.  
  12.         currentSelection.Range.Text = textToInsert;
  13.         currentSelection.EndKey(WdUnits.wdStory);
  14.  
  15.         return retval;
  16.     }
  17.  
  18.     private void ObjButtonAddFoo_Click(object sender, RibbonControlEventArgs e)
  19.     {
  20.         if (ReplaceText("REPLACEMENT TEXT"))
  21.         {
  22.             Microsoft.Office.Interop.Word.Selection currentSelection = Globals.ThisAddIn.Application.Selection;
  23.             currentSelection.TypeParagraph();
  24.         }
  25.     }
  26.      
  27. private bool ReplaceText(string textToInsert)
  28.     {
  29.         bool retval = false;
  30.  
  31.         Microsoft.Office.Interop.Word.Selection currentSelection = Globals.ThisAddIn.Application.Selection;
  32.  
  33.         // if (currentSelection.ContainsTrailingParagraphMark)
  34.         // {
  35.         //    retval = true;
  36.         // }
  37.  
  38.         //Remove the paragraph mark from the range to preserve it
  39.         object charUnit = Microsoft.Office.Interop.Word.WdUnits.wdCharacter;
  40.         object move = -1;  // move left 1
  41.         currentSelection.MoveEnd(ref charUnit, ref move);
  42.         currentSelection.Range.Text = textToInsert;
  43.  
  44.         currentSelection.EndKey(WdUnits.wdStory);
  45.  
  46.         return retval;
  47.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top