Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement