Results 1 to 8 of 8
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trap menu commands (Word2000+)

    I have previously plagiarised code to trap specific commands/events, especially Save, saveAs, Close, Alt-F4, Ctrl-F4 and so on, but am now struggling to be more generic.

    Take "bolding" for example.

    1) I can trap the use of the regular Bold button, no matter where/on which toolbar it is placed:<pre>Sub TESTcb()
    Dim cb As CommandBar
    Dim cbc As CommandBarControl
    For Each cb In Application.CommandBars
    For Each cbc In cb.Controls
    If cbc.Caption = "&Bold" Then
    cbc.OnAction = "MyTrap_Bold"
    Else
    End If
    Next
    Next
    End Sub
    Sub MyTrap_Bold()
    MsgBox "I trapped you!"
    End Sub</pre>


    2) I can trap the shortcut key combination:<pre>Sub Testkey()
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, wdKeyB), KeyCategory:=wdKeyCategoryMacro, Command:="MyBold"
    End Sub
    Sub MyBold()
    MsgBox "here in my bold land"
    End Sub</pre>


    3) I can use Tools, Macro, macros, "Word commands", locate the name of a macro "Bold", then switch to "macros in Normal.dot" and use the Create button to generate and modify:<pre>Sub Bold()
    ' Bold Macro
    ' Makes the selection bold (toggle)
    MsgBox "Selection.Font.Bold = wdToggle"
    End Sub</pre>


    But for the life of me, as they say, I can't work out how I might trap the user's use of Format, Font, Font style, Bold.

    I spent an hour last night looking through old posts (in which I took part and took information) for trapping keys, keybindings etc, but trapping and monitoring a sequence such as Alt-O, F, Alt-Y, "B" etc, or a sequence of tab/Shift-Tab keys as the user navigates a dialogue box seem like a great waste of effort. Furthermore I'd also have to trap clicks on Format, Font, Bold in the same vein.

    I feel that I've gotten in too deep to see where I should be going.

    Trapping the commands for bolding would be a starting example of other devices, e.g. changing indentation, generating a table.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap menu commands (Word2000+)

    I have since learned how to trap the Format, Font dialogue box (using the Word Commands/Create trick)<pre>Sub FormatFont()
    ' FormatFont Macro
    ' Changes the appearance of the selected characters
    MsgBox "Dialogs(wdDialogFormatFont).Show"
    End Sub</pre>


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

    Re: Trap menu commands (Word2000+)

    As you have found, you can hijack the Format | Font dialog. You can then check whether the user selected Bold after the user has closed the dialog and act accordingly.
    But as far as I know, you can't trap the user selecting Bold in the Font dialog while it is open.

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Trap menu commands (Word2000+)

    Are you going to trap someone using the organiser to copy in a style that has the bold font attribute set?
    How about if they apply the Strong character style?

    StuartR

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap menu commands (Word2000+)

    Thanks, Stuart for the nudges.

    >Are you going to trap someone using the organiser to copy in a style that has the bold font attribute set?
    Depends on the client. We are assuming that users want to please the client (as with Jefferson's comments at the foot of <post:=166,961>post 166,961</post:>).
    Part of the thrust is to encourage use of styles. If someone wants to hijack styles and is determined to do so, no client (that I've met) is going to pay me to completely re-write Word.
    That said if Organiser causes problems, the client might ask that it be trapped.

    >How about if they apply the Strong character style?
    Ah! that's what we want (for styles).
    For example, we have a character style csB which applies Bolding. We want to trap all regular ways and means (buttons, shortcut keys, menu commands) of applying Bold, and apply our character style.
    The user need not and probably doesn't want to know. They want to continue using Ctrl-B and seeing the text locally bold.

    For each "good/bad practice" that we can identify, we want to explore the option of steering the user towards the Good practice, to assist them to be good, so to speak.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap menu commands (Word2000+)

    >after the user has closed the dialog
    Thanks Hans.
    (thinks: Oh good; I get to play around with all that .Display, .Show, .Execute stuff again ....)

  7. #7
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Trap menu commands (Word2000+)

    Hi Chris
    I have not been able to grasp the end goal which you envision for your code. Are you trying to limit the paragraph styles being applied to the document(s)?
    Regards
    Don

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap menu commands (Word2000+)

    > I have not been able to grasp the end goal which you envision for your code. Are you trying to limit the paragraph styles being applied to the document(s)?
    No, not as restrictive as that.
    We want to assist users by encouraging them to do "good things" and discourage them from doing "bad things".

    The client will define for us what are the Good Things and what are the Bad Things.
    Could be anything; client's decision. (We happen to have a pretty good list of good and bad practices, and we'll use that as suggestions to get the client thinking).

    At this point nothing has been defined as good/bad, but one thing we do know: Whenever a user does a Good Thing, or a Bad Thing, they will be either clicking with a mouse (on a button or a menu command) or tapping a key(combination).

    In consequence I feel that as long as I can trap a clicking with a mouse (on a button or a menu command) or a key(combination), then I can examine the command being used, and implement the encouragement/discouragement technique required by the client.

    The classic example happens to be local formatting and styles - please use a character style for bold rather than clicking on the toolbar button "B"old.
    If I can hijack the Ctrl-B and "B" button click and apply the character style csB to the selected text, we will have diverted the user away from local formatting while allowing them to click/Ctrl-B quite happily, as they are accustomed.

    A second example might be tables. Suppose the client has decided that all tables created in documents ought to be laid out and formatted in a specific way. Then we might want to trap command sequences that violate these rules and at least ask the user if they really intend to be non-standard. In the worst case we would just hammer our layout and formatting regardless of what they choose, although I am against the "hammer" approach. In this case I'd want to trap/detect the use of the menu sequence Table, Insert, Table, regardless of whether it was clicked or keyboarded. I'm not about to try and detect the user who writes a macro to insert a table.

    A third example might be Spell-checking. We might be asked to analyze the document text and determine if accented characters are present, or if specific buzzwords are present. In those cases we might automatically rope in especial custom dictionaries, just to save the user having to think about it. ("Oh darn! i forgot i was in a French Medical text .....")

    If the client asks me to detect any inactivity exceeding three minutes I'd probably baulk at that ("Hey! get back to work!").

    At this stage we don't know exactly what the client will want, but we are sure it will involve some monitoring of specific mouse clicks or keyboard taps.

Posting Permissions

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