How to override "Ctrl+F"

63 views
Skip to first unread message

John

unread,
Dec 14, 2008, 9:59:49 PM12/14/08
to excel vba
I have been trying to override the "Ctrl+F" functionality using
Application.OnKey like below.

Private Sub Workbook_Activate()
Application.OnKey "^f", "FindByValue"
Application.OnKey "^F", "FindByValue"
End Sub


Private Sub Workbook_Deactivate()
Application.OnKey "^f"
Application.OnKey "^F"
End Sub

This is working great. But it disables Ctrl+F for other workbooks that
are open i.e On Ctrl+F nothing happens in other workbooks. Every other
key combination(tried Ctrl+C, Ctrl+X etc) works. Seeing this problem
only with "Ctrl+F". What is special about it and how can I override it
without this issue?

Thanks

wanderer

unread,
Dec 15, 2008, 4:13:28 AM12/15/08
to excel vba
Hi John!

In your programe, you used 2 method "Activate" & "Deactivate" .
"Workbook_Deactivate" must be invoked before you activate a new
workbook.
So the macro "FindByValue" has already been set disabled.

if you want this macro can be used in all the workbooks,
you can try "Workbook_Open" & "Workbook_BeforeClose".

Good luck!

Sreekanth Kollu

unread,
Dec 15, 2008, 11:53:01 AM12/15/08
to exce...@googlegroups.com
Hi,
Thanks for the response.
The Deactivate event gets called when ever the current workbook loses focus. So it is getting invoked(e.g. Alt+Tab to another Excel workbook OR close the current workbook).
 
One interesting thing I noticed is, I kept the below statements together just to see the behavior of "Ctrl+F".
Application.OnKey "^f", "FindByValue"
Application.OnKey "^F", "FindByValue"
Application.OnKey "^f"
Application.OnKey "^F"

I was hoping the above statements should not have any effect. But after executing the above statements, "Ctrl+F" no longer works even on the same sheet. Nothing happens for "Ctrl+F". I was hoping to see the default behavior of "Ctrl+F".
 
Do I need to implement this in a different way? Like override built-in command bar event or something? Please advise..
 
Thanks

John

unread,
Dec 16, 2008, 12:35:22 AM12/16/08
to excel vba
If it helps, I have tried having this statement

Application.CommandBars("Worksheet Menu Bar").Controls
("Edit").Controls.Item("Find...").Reset

in the hope of resetting the functionality of the Find command button
or Ctrl+F. Does any one have any idea why I am losing the default Ctrl
+F functionality as well as Find button functionality also.

Any help is greatly appreciated.

Thanks




On Dec 15, 8:53 am, "Sreekanth Kollu" <kollu.sreeka...@gmail.com>
wrote:
> Hi,
> Thanks for the response.
> The Deactivate event gets called when ever the current workbook loses focus.
> So it is getting invoked(e.g. Alt+Tab to another Excel workbook OR close the
> current workbook).
>
> One interesting thing I noticed is, I kept the below statements together
> just to see the behavior of "Ctrl+F".
> *Application.OnKey "^f", "FindByValue"
> Application.OnKey "^F", "FindByValue"*
> *Application.OnKey "^f"
> Application.OnKey "^F"*
> > > Thanks- Hide quoted text -
>
> - Show quoted text -

wanderer

unread,
Dec 20, 2008, 3:25:59 AM12/20/08
to excel vba
Hi, John
First, I don't know what do you want exactly.
If you just want to use "Ctrl+f" as usual, why not delete these code
lines.

if you just kept the statements together,
I think that "Ctrl+f" should be working well.

In the first reply of you, have these lines.
*Application.OnKey "^f", "FindByValue"
Application.OnKey "^F", "FindByValue"*
*Application.OnKey "^f"
Application.OnKey "^F"*
I don't know what the "*" is . --maybe comment flag (" ' ")?
if so, "Ctrl+f" can also work well, and "Ctrl+Shift+f" was replaced.(F
= Shift+f, right?)

so, I was confused.

If you havn't got the answer, you can mail to me.
Reply all
Reply to author
Forward
0 new messages