Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Sep 2005
    Location
    Poughkeepsie, New York, USA
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simulating Mouse Action in VBA (Word 2003)

    Is it possible to simulate mouse button presses in Word VBA? I am trying to accomplish the following in VBA:

    1. Move my cursor 1 character to the left
    2. Simulate a Mouse Right Click
    3. Simulate a Mouse Left Click
    4. Move my cursor 1 character to the right

    The purpose of the Right Click is to bring up the context-sensitive menu; the purpose of the Left Click is to dismiss the context-sensitive menu.

    Thanks.

  2. #2
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simulating Mouse Action in VBA (Word 2003)

    Can you not find the menu from one of the menu bars at the top of the screen? If so, you should be able to use the macro recorder to find the necessary code... <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What&#39;s more, you deserve to be hacked." -Richard Clarke

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Simulating Mouse Action in VBA (Word 2003)

    1/4) Selection.MoveLeft and Selection.MoveRight will move the insertion point one character to the left/right.
    2/3) If you want to perform a specific action from the popup menu, there is no doubt a VBA equivalent for it, but it makes no sense to display and dismiss the popup menu in a macro, the user can't do anything with it.

  4. #4
    2 Star Lounger
    Join Date
    Sep 2005
    Location
    Poughkeepsie, New York, USA
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simulating Mouse Action in VBA (Word 2003)

    Hans,

    I know it doesn't seem to make sense but in fact it does accomplish something.

    In an earlier request for help, you provided VBA code that would reload a custom dictionary after adding a word to it so that the word would no longer be considered misspelled. Although the dictionary reloads, the red squiggles indicating that the word is misspelled do not disappear unless I right-click on the word. This is what I am trying to accomplish -- simulating my right-clicking on the word.

    I tried to approach it by writing code to select IgnoreAll before selecting the word for inclusion in the custom dictionary, but I was unable to figure out code that would accomplish that task.

  5. #5
    2 Star Lounger
    Join Date
    Sep 2005
    Location
    Poughkeepsie, New York, USA
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simulating Mouse Action in VBA (Word 2003)

    Thanks, Jeremy, but I can't duplicate the task that way.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Simulating Mouse Action in VBA (Word 2003)

    Does this do what you want?

    SendKeys "{Esc}"
    CommandBars("Spelling").ShowPopup

  7. #7
    2 Star Lounger
    Join Date
    Sep 2005
    Location
    Poughkeepsie, New York, USA
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Simulating Mouse Action in VBA (Word 2003)

    Perfectly, Hans. Again, I thank you.

Posting Permissions

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