We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

shortcut key to call an Add in.  In particular Find And Replace

rberke
rberke asked
on
Medium Priority
317 Views
Last Modified: 2012-08-13
------------- Question ---------------------

I want to be able to call certain addins quickly.
In particular, I often use Rick Frasier's Find and Replace.

Ctrl M F would be perfect.

How can I do that?  

------------- Back ground ---------------------


For future flexibility, I am writing a program that lets me choose from a bunch of functions

I'll use Autokeys to assign  ctrl M to runcode fncShortCutAsker()

public function fncShortCutAsker()
  s = inputbox "what to do?"
  select case lcase(trim(s))
  case "f"
        Msgbox "I don't yet know how to call Find and Replace"
  case else
        msgbox s & " is not a valid shortcut"

  end select
end function
Comment
Watch Question

Leigh PurvisDatabase Developer
CERTIFIED EXPERT

Commented:
Without knowing the details of how that AddIn is loaded (i.e. in code or whatever) you can create an AutoKeys macro with a key combination that will let you fire a function that calls the Method you require?
rberkeConsultant

Author

Commented:

The key question is "how to know the method".

For instance, In Excel and Word, I can turn on macro recorder,  the execute my desired function.

Access does not have such a function.

Perhaps someone knows how to dig into the menu system and pull a method from a menu name out of that?

In this particular case, I can email Rick Fisher, the author and ask.  But,
  #1)  I hate to bother Mr. Fisher for something so trivial
  #2)  in general, some addins might not give an email address


Leigh PurvisDatabase Developer
CERTIFIED EXPERT

Commented:
How do you currently execute it?
rberkeConsultant

Author

Commented:
I executed it like I do all of my addins, from the access menu bar.  

Tools > Add Ins  > takes me to a list of the addin that I have installed. I then choose the one that says Find and Replace.
rberke,
here is a comprehensive list of built in shortcut keys for Access.  I did not see a built-in shortcut for add-ins, so I guess the only solution would be to find a 3rd party macro recorder for access.

http://www.rnib.org.uk/xpedio/groups/public/documents/PublicWebsite/public_rnib003596.hcsp

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
MIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012
Commented:
rberke,

As far as I know, key Combinations like Ctrl M F are not allowed in Access. (You can only have one letter)

Might I suggest Ctrl-Shift-M?

Create an AutoKeys Macro as LPurvis suggests.

(The name of this macro must be AUTOKEYS)

Open a New Macro
Save it as: AutoKeys
Click: View-->Macro Names
Macro Name:  ^+m
Action: SendKeys
KeyStrokes: "%{T}{I}{YourAddInHotkeyGoesHere}"
Wait: No

Here is the explanation
"^" is the Control Key
"+" is the Shit Key
"m" is the letter you want to press last to run the macro. Thus the macro runs when you press:
Control-Shift-m

The "Sendkeys" statement simulates keystrokes
"%" is the Alt
{X} is a keystroke
"Wait" Specifies whether the macro should pause until the keystrokes have been processed. Yes (to pause) or No (not to pause)

So...

If the hot key in your Add In menu for your Find and Relace Addin is "r", then your Sendkeys would look like this:
KeyStrokes: "%{T}{I}{R}"

Make sense?

It works, I tested it.

Now LPurvis, will probably dissaprove of my use of  Sendkeys. (And yes Sendkeys does have it's drawbacks)
;)
But...
<LP, yes I tried RunCode with an argument of a function that performed the Sendkeys, but I could not get it to work.....getting sleeeeeeepy>


Jeff


Leigh PurvisDatabase Developer
CERTIFIED EXPERT
Commented:
Well.... ;-)

If there's no obvious function call to invoke your addin then so be it.
You might want to consider the slightly safer API wrapped version
http://www.mvps.org/access/api/api0046.htm

rberkeConsultant

Author

Commented:
It works!    My autokeys  uses ^m  runcode fncShortCutAsker()  

My vba then calls SendKeys as follows

  public function fncShortCutAsker()
  s = inputbox "what to do?"
 
  select case lcase(trim(s))
  case "f"
        sleep (5000)   ' see note below
        SendKeys "%{T}{I}{a}"
  case else
        msgbox s & " is not a valid shortcut"
  end select
  end function

But, exactly how dangerous is this?  

For instance LPurvis's link says
  SendKeys is not recommended in a production environment.  This is because the keystrokes are processed by whichever window is currently active on the desktop.  Obviously this will cause unpredictable behavior
  in case another app receives the focus while your code is processing

I tried to simulate another app receiving focus by putting in a sleep (5000) . I switched to Word, but the keystrokes never seemed to go into Word they just disappeared

Naturally, I removed the sleep function.  

My guess is that it is a pretty safe solution to my problem, especially since users will never use it, only me.

Leigh PurvisDatabase Developer
CERTIFIED EXPERT

Commented:
Sendkeys processes regardless of what the current window (and hence even application) is.
So all things being equal - it looks flawless.
And if you're the only one using it then what's the harm (but keep an eye on your Numlock - Sendkeys is buggy - that's one of the reasons for the trepidation - hence the point of the link's code)

However (just as an example here) if you were on a dog of a machine (users - hard to predict the crap they'll have installed) then if the window changed before the code completed then the sendkeys would try to fire on whatever active window it found.

If it works for you and you're happy with it then go for it.
(I'd still have like to find the library and function to perhaps call directly - but I don't currently have any add-ins installed to try it for you).
Jeffrey CoachmanMIS Liason
CERTIFIED EXPERT
Most Valuable Expert 2012

Commented:
rberke,
Glad I could help.
My guess from your post is that you had a pretty good idea about what you wanted.
I posted my solution as just an alternative so you could just "Get it done".
I had noticed that the Q was open for about a month.

You might want to drop the Rick Fisher a line and ask him if (As LPurvis states) there is a way it invoke the add-in via code.


LPurvis,
I even tried to simulate navigating the menu commands via VBA, but no luck.
Yes, I rarely use send keys because of the way it works around dialog boxes.
I have NEVER used it to simulate more than 3 keystrokes.
I use it mainly temporarily to "Make" something happen if I am testing some code.

Interestingly enough, I ued to use Sendkeys all the time, when I would set focus to a text box and simulate pressing the F2 function key to put the user in "Edit" mode.
    SendKeys "{F2}"

That is, until YOU taught me to use SelStart!:
    txtSearch.SelStart = Nz(Len(txtSearch))
:)
Leigh PurvisDatabase Developer
CERTIFIED EXPERT

Commented:
:-D
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.