Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Clipboard.SetText(text);
- ...
- var foregroundWindow = GetForegroundWindow();
- if (GetWindowText(foregroundWindow, aString, 256) > 0)
- {
- appName = aString.ToString();
- if (appName.IndexOf("Word") > 0)
- {
- Microsoft.Office.Interop.Word.Application wdApp = null;
- wdApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
- if (wdApp != null)
- {
- Microsoft.Office.Interop.Word.Selection currentSelection = wdApp.Selection;
- // Store the user's current Overtype selection
- bool userOvertype = wdApp.Options.Overtype;
- // Make sure Overtype is turned off.
- if (wdApp.Options.Overtype)
- {
- wdApp.Options.Overtype = false;
- }
- // Test to see if selection is an insertion point.
- if (currentSelection.Type == Microsoft.Office.Interop.Word.WdSelectionType.wdSelectionIP)
- {
- currentSelection.TypeText(aString);
- }
- else
- {
- if (currentSelection.Type == Microsoft.Office.Interop.Word.WdSelectionType.wdSelectionNormal)
- {
- // Move to start of selection.
- if (wdApp.Options.ReplaceSelection)
- {
- object direction = Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseStart;
- currentSelection.Collapse(ref direction);
- }
- currentSelection.TypeText(aString);
- }
- }
- // Restore the user's Overtype selection
- wdApp.Options.Overtype = userOvertype;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement