RE: Problem Overriding Word menu items using VSTO 2005... Shortcuts no

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Shawn,

The code that you've implemented essentially allows you to hook the click
event of the Paste button, however, using the CTRL+V keyboard shortcut to
execute the paste would not execute the click event of the Paste menu item
which is why your code isn't getting executed.

There are a couple of ways that I've found that would allow you to trap and
override the CTRL+V shortcut.

1. Create a keyboard hook which would allow you to trap and handle a
scenario where the user presses CTRL+V.

For more information regarding using a keyboard hook take a look at the
following MSDN documentation.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/lowlevelkeyboardproc.asp

2. Another option that is easier to implement and appears to handle not
only the scenario where a user presses CTRL+V but also if the user clicks the
Paste item on the menu is to add a VBA macro to the Microsoft Word document
named EditPaste.

Example
=============
Sub EditPaste()
MsgBox "Pasting"
End Sub
=============

Hope this helps!

If you have any questions please let me know via the posting.

Regards,

Ken Laws
Microsoft Support


This posting is provided "AS IS" with no warranties, and confers no rights.

For more information regarding Visual Studio Tools for Office 2005:

Best of Blogs: Visual Studio 2005 Tools for Office
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_2003_ta/html/odc_landvsto2005_ta.asp

Visual Studio Tools for Office Forum
http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=16

Visual Studio Tools for the Microsoft Office System
http://msdn.microsoft.com/office/understanding/vsto/default.aspx


"Shawn Hogan" wrote:

> Hi Everyone,
>
> I'm trying to override the menu Paste item using VSTO 2005 but I'm having
> problems. It seems that if i click the menu item(Edit\Paste or right click
> paste) my event code works but if i use the shortcut keys(CTRL-V) my event
> code does not fire.
>
> What i've done so far is obtain the paste menu item from Word using the
> command bars object like so:
>
> Declare my object as
> private withevents pasteMenuItem as microsoft.office.core.commandBarButton
>
> in Startup i have
> pasteMenuItem = thisdocument.CommandBars("Edit").controls("Paste")
>
> In the click event of the menu control i put a message box just to show me
> that it fires...
> Msgbox "pasting"
>
> What am i doing wrong? Any workarounds? Any alternate methods?
>
> Thanks,
> Shawn
>
>
>
>
.



Relevant Pages

  • Re: Keyboard hook from Windows Service
    ... I am trying to write a service to hook the keyboard. ... The actual keyboard hook is in a DLL. ... I would like to execute SetWindowsHookEx without user intervention, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Windows xp screen freezing...randomly
    ... Enquire, plan and execute ... After it finished booting plug in the keyboard ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Windows xp screen freezing...randomly
    ... Enquire, plan and execute ... After it finished booting plug in the keyboard ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Intellectual Property Protection
    ... I can just pop up the character map (or any other onscreen keyboard) and type whatever I want. ... It seems to me that what I should do is hook the keyboard, ... and compare it to a database of copyrighted works. ... Blanking one makes the use compliant with the license. ...
    (microsoft.public.development.device.drivers)
  • Re: Which program file is executed?
    ... How do I know what program (folder and file name) is executed when I click on shortcut? ... For some shortcuts, the answer seems self-evident: right-click on the shortcut icon, click on Properties, and look at Target in the Shortcut tab. ... When I execute a program from the Start> Run window, how can I determine the full path that is executed? ... When you type the name of a program at the Command Prompt then the executable must either reside in the current folder or in one of the folders listed in the %path% variable. ...
    (microsoft.public.windowsxp.general)