none
Using Multiple Sendkeys toggles Numlock RRS feed

  • Question

  • Because there is a bug with VBA code picking from the ReferenceKind in the crossreference popup, I am forced to use send keys to make the change.  It works fine accept that it toggles on and off numlock.  After researching it, I found using multiple sendkeys together will toggle numlock.  The resolution was puting DoCommand between each sendkey.  This crashes Word.  Any suggestions on what I can put in between the sendkeys?

        With Dialogs(wdDialogInsertCrossReference)
          SendKeys "%t"
          SendKeys "+(heading)"
          SendKeys "{enter}"
          SendKeys "%r"
          SendKeys "{down 3}"
          SendKeys "{tab}"
          SendKeys "+{+}"
          SendKeys "{enter}"
          .Show
       End With

    Thanks,

    Debra Ann


    DebraAnn

    Saturday, March 1, 2014 2:07 PM

Answers

  • This works for me:

    With Dialogs(wdDialogInsertCrossReference)
        .ReferenceType = wdRefTypeHeading
        .ReferenceKind = wdNumberNoContext
        SendKeys "%h", True
        .Show
    End With

    As does:

    With Dialogs(wdDialogInsertCrossReference)
        SendKeys "%t", True
        SendKeys "+(heading)", True
        SendKeys "{enter}", True
        SendKeys "%r", True
        SendKeys "{down 3}", True
        SendKeys "{tab}", True
        SendKeys "+{+}", True
        SendKeys "{enter}", True
        .Show
    End With


    Cheers
    Paul Edstein
    [MS MVP - Word]




    Monday, March 3, 2014 1:46 AM
  • Neither of these worked for me.

    The first piece of code, I tried before but RefenceKind does not change.

    The second piece of code (adding true to the end of each sendkeys line), numlock still turns off and on

    Any other ideas?


    That suggests there may be a fault in your Office installation, since both work for me. Have you tried repairing the Office installation (via Programs & Features > Microsoft Office > Change in the Windows Control Panel)?

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, March 3, 2014 6:59 PM

All replies

  • This works for me:

    With Dialogs(wdDialogInsertCrossReference)
        .ReferenceType = wdRefTypeHeading
        .ReferenceKind = wdNumberNoContext
        SendKeys "%h", True
        .Show
    End With

    As does:

    With Dialogs(wdDialogInsertCrossReference)
        SendKeys "%t", True
        SendKeys "+(heading)", True
        SendKeys "{enter}", True
        SendKeys "%r", True
        SendKeys "{down 3}", True
        SendKeys "{tab}", True
        SendKeys "+{+}", True
        SendKeys "{enter}", True
        .Show
    End With


    Cheers
    Paul Edstein
    [MS MVP - Word]




    Monday, March 3, 2014 1:46 AM
  • Neither of these worked for me.

    The first piece of code, I tried before but RefenceKind does not change.

    The second piece of code (adding true to the end of each sendkeys line), numlock still turns off and on

    Any other ideas?  Is it possible to test numlock being true or false, put it in a varible, and then at the end of the code have numlock equal whatever it did in the beginning? If so, what would be the code for testing numlock's state?

    Thanks for any assistance.

    DebraAnn


    DebraAnn

    Monday, March 3, 2014 1:19 PM
  • I added the following and so far a few people have tested and it is working.  Try it out:

        Dim NLState As Byte
       
        NLState = wdNumLock
       
        With Dialogs(wdDialogInsertCrossReference)
       
          SendKeys "%t", True
          SendKeys "+(heading)", True
          SendKeys "{enter}", True
          SendKeys "%r", True
          SendKeys "{down 3}", True
          SendKeys "{tab}", True
          SendKeys "+{+}", True
          SendKeys "{enter}", True
          .Show
       End With

        SetNumLockKey = NLState


    DebraAnn

    Monday, March 3, 2014 2:07 PM
  • Neither of these worked for me.

    The first piece of code, I tried before but RefenceKind does not change.

    The second piece of code (adding true to the end of each sendkeys line), numlock still turns off and on

    Any other ideas?


    That suggests there may be a fault in your Office installation, since both work for me. Have you tried repairing the Office installation (via Programs & Features > Microsoft Office > Change in the Windows Control Panel)?

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, March 3, 2014 6:59 PM
  • Microsoft article 179987 states this is a bug and suggests adding DoEvents between each line.  For example,

        With Dialogs(wdDialogInsertCrossReference)
          SendKeys "%t"
          DoEvents
          SendKeys "+(heading)"
          DoEvents
          SendKeys "{enter}"
          DoEvents
          SendKeys "%r"
          DoEvents
          SendKeys "{down 3}"
          DoEvents
          SendKeys "{tab}"
          DoEvents
          SendKeys "+{+}"
          DoEvents
          SendKeys "{enter}"
          .Show
       End With
    Monday, June 30, 2014 6:46 PM
  • I tried this last solution and it does not work for me.  As soon as the Sendkeys command is issued, the NUM LOCK turns off.
    Monday, October 6, 2014 3:25 PM
  • Regardless of the approach taken, manipulating the dialog performs inconsistently.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, October 6, 2014 9:38 PM