Getting an error when the Word add-in is run

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tejas1sastry
    New Member
    • Oct 2014
    • 1

    Getting an error when the Word add-in is run

    I want to copy the word entered by a user as soon as the user presses space(Just like the spell checker in word editors do). I'm using the following code:
    Code:
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            ConsoleKeyInfo info = Console.ReadKey();
            if (info.KeyChar == ' ')
            {
                Word.Range rng = this.Application.ActiveDocument.Words.Last;
                rng.Select();
                rng.Copy();
                String input = Clipboard.GetText(TextDataFormat.Text);
            }
        }
    I'm getting the following error:
    An exception of type 'System.Invalid OperationExcept ion' occurred in mscorlib.dll but was not handled in user code.

    For the following line:
    Code:
    ConsoleKeyInfo info = Console.ReadKey();
    Last edited by Frinavale; Oct 20 '14, 03:09 PM. Reason: Added code tags. Please post code snippets in code tags to make it easier for the experts to read the code and refer to lines within it while helping you.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What type of application are you implementing?

    Comment

    Working...