Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is it possible to intercept user actions? (Word 2000/XP)

    Hi,

    I am developing a Word VBA application which will aim to prevent users from doing certain things. Ie. When they attempt to insert a table within a header or footer, a message box will pop up telling them this is not a good idea. Also, if they attempt to change or create a new style, a message box will appear telling them 'This is not possible with the current security setting'. These are just examples.

    Is it possible to intercept user actions this way? Or are we just restricted to intercepting the AutoOpen, AutoClose, AutoSave etc commands?

    Before I waste a lot of time trying to develop this, any advice would be much appreciated [img]/forums/images/smilies/smile.gif[/img]

    Thanks,

    -- Chris

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

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    You can intercept most user actions by creating a macro with the same name as a built-in command. For instance, the command behind the Insert Table button on the General toolbar is InsertTableGeneral.

    Example:

    Sub InsertTableGeneral()
    MsgBox""This is not a good idea.", vbCritical
    End Sub

    You can see a list of all commands by selecting Tools/Customize..., Commands tab, All Commands category. You can also download a list of all commands with descriptions etc. from here.

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

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    In the Word Commands list you can download from the link to MVPS site I posted in my earlier reply, there are comments on which menu items and toolbar buttonswill not be intercepted by a macro.

  4. #4
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    Hans,

    That is golden, thanks!

    -- Chris

  5. #5
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    Thanks Hans,

    My mistake...

    It works perfectly now [img]/forums/images/smilies/smile.gif[/img]

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

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    Additional remark: a Bold() macro should intercept the B toolbar button and the Ctrl+B shortcut, but it won't do anything if you select Format/Font... and set bold.

    If you select Tools/Macro/Macros... (or type Alt+F8), enter Bold in the Macro Name box and click Create (or Make, don't know the exact caption in English), you should get a macro with the standard action, ready for you to modify. This is what I get in Word 97 (Dutch):

    Sub Bold()
    '
    ' Bold Macro
    ' De selectie vet maken (wisseloptie)
    '
    Selection.Font.Bold = wdToggle

    End Sub

  7. #7
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    Hmmm. Interesting.

    Is it possible then to intercept the user action when they take the 'Format/Font...' route? What a pain Microsoft didn't include this within the Bold() macro routine.

    Also, do you know if it is possible to intercept user actions which are not part of the Word Command list? I am sure the answer is no, but would accessing the API or a similar low level layer make this possible?

    I am clutching at straws!

    Thanks,

    Chris

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

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    (1) Please take a look at the list of commands. You will see find the FormatFont command - this intercepts the menu option.

    (2) Perhaps somebody can help you if you state what kind of user action (that is not in the commands list) you would like to intercept.

  9. #9
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    I guess what I am alluding to is whether it is possible to intercept what the user is doing (ie keystrokes etc). It is a little vague and maybe suited for a later post when I have more specifics.

    Thanks again Hans,

    Chris

  10. #10
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Edison, New Jersey, USA
    Posts
    215
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    This was an AWESOME Post!!! So helpful, to myself anyway [img]/forums/images/smilies/smile.gif[/img]
    CSF - if you wouldn't mind shareing, I'd love to see some of your solutions....

    -Jody

  11. #11
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    Sure Jody [img]/forums/images/smilies/smile.gif[/img]

    One further question (Hans...help on this one would be greatly appreciated [img]/forums/images/smilies/smile.gif[/img]

    Here is a more specific example of what I need to do:

    Our users have a lot of difficulty with the Table Of Contents command:

    'Insert -> Reference -> Index and Tables -> Table Of Contents -> OK'

    I really need to be able to intercept this command. However, when I use the 'InsertTableOfContents' command nothing happens.

    Any ideas on how I might intercept the user at this point?

    Thanks,

    Chris

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

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    The InsertIndex and InsertTableOfContents commands display just one tab of the Index and Tables dialog. The Insert/Index and Tables menu option executes the InsertIndexAndTables command. As you see, in many cases, the command name is just the menu name followed by the menu option, with all spaces removed.

  13. #13
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    I see what you are saying, but intercepting the user at the 'Insert -> Reference -> Index and Tables' stage would be too restrictive if the user only wished to add an index or something of that sort. Would it be possible to intercept when the user clicks on the 'Table of Contents' tab within 'Index and Tables'?

    Thanks, Chris

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

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    I'm out of my depth now. Windows API gurus will no doubt know how to do that...

    You could replace the InsertIndexAndTables command by a question whether the user wants to insert an Index or a TOC or ... (this could be done with MsgBox instructions, or a UserForm if you want to be fancy). Then, you could display the dialog with the appropriate tab selected (see Dialogs), together with your custom code.

  15. #15
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is it possible to intercept user actions? (Word 2000/XP)

    Anybody out there know how to do this?

    Calling all API gurus!!

    [img]/forums/images/smilies/smile.gif[/img]

Page 1 of 2 12 LastLast

Posting Permissions

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