Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Feb 2014
    Posts
    12
    Thanks
    0
    Thanked 1 Time in 1 Post

    Sendkeys in Macros and use of shortcuts

    Further to a thread that I started a few weeks ago on launching the autocorrect dialogue via VBA.

    I was able to get my macro developed using the method given, which included the use of Sendkeys.

    My problem arose when attaching a shortcut to the macro. To simplify the problem I have the following code in a macro

    With Application.Dialogs(wdDialogToolsAutoCorrect)
    VBA.SendKeys "test"
    .Show
    End With

    1) When I run the macro from the developer tab, the autocorrect dialogue opens and sendkeys inserts the required text.

    2) I then attached the macro to a shortcut key in Normal.dot

    3) When I use the shortcut key, the autocorrect dialogue opens BUT sendkeys does not work, the text isnt there.

    4) However, it still works fine if I run the same macro from the developer tab

    Is there some document "focus" being lost because the shortcut is stored in Normal.dot? - Or is something else going on? - Or am I going nuts? (possible).

    Any help appreciated. Thanks.

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,514
    Thanks
    3
    Thanked 143 Times in 136 Posts
    I don't know why you are having the problem but it is most likely due to SendKeys losing focus. Try a version without SendKeys
    Code:
    Sub WotThe()
      With Application.Dialogs(wdDialogToolsAutoCorrect)
        'Word2013 Dialog arguments are: ShowFineTuner , CapTable, InWordMail, InitialCaps, SentenceCaps, Days, CapsLock, ReplaceText, Formatting, Replace, With, Add, Delete, SmartQuotes, CorrectHangulAndAlphabet, ConvBrackets, ConvQuotes, ConvPunct, ReplaceTextFromSpellingChecker
        .Replace = "test"
        .Show
      End With
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #3
    New Lounger
    Join Date
    Feb 2014
    Posts
    12
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Andrew
    Thanks for the insight. I found that passing the values as you indicated worked OK - up to a point.

    Using the sendkeys function invokes the "lookup" feature of autocorrect, this looks for entries and adjusts what it finds as the keys in the name change with typing.

    Using the method above loads the characters into the fields but requires the use to edit one of the fields before autocorrect can set up for an add or replace. I also found that the send keys worked fine when loaded from the quick action bar, but there is something strange about the way Word looses focus with shortcut keys stored in Normal.dot.

    I'd welcome any thoughts anyone has on this.

    I have used the technique to automatically lookup and add abbreviations for a typing productivity toolset aimed at technical writers and business analysts. You'll see that I have stuck with the shortcut keys method in order to keep fingers on he keyboard in a volume text entry environment. Details here if anyone is interested

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •