Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Take Focus on Click (Word 2007)

    I read something about setting the TakeFocusOnClick property to False for a Command Button control to avoid giving focus to the Button when clicked. The idea was to keep the focus in the Word document when clicking buttons on a dialog with modality = False. This would permit a user from to function similarly to toolbar and focus would remain in the document.

    I want to display a non-modal dialog with buttons that insert text or special characters into the dialog. I would prefer that focus remain in the document, not on the form. All buttons have TakeFocusOnClick set to False. But the first button in the form takes focus when the form loads... and retains focus. Clicking a button successfully adds text to the document at the insertion point, but I must click in the document to get focus back to the document, rather than being able to continue typing after clicking the button.

    Have I misunderstood the function of TakeFocusOnClick, or is there some other way that I can give focus back to the document (without closing the user form)?

    Thanks,
    Richard Barrett

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

    Re: Take Focus on Click (Word 2007)

    The behavior that you describe is the way built-in modeless dialogs work, such as the 'mark index entry' dialog - you have to click in the document to be able to select text or type.

    You can add a line

    AppActivate "Microsoft Word"

    at the end of the On Click code to set focus back to the document (cf <post:=710,652>post 710,652</post:>)

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Take Focus on Click (Word 2007)

    Thank you, Hans.

    I tried

    AppActivate "Microsoft Word"

    (the post you referenced was from you to me), but run-time error "Invalid Procedure or Function" occurs. I've tried .Activate and .SetFocus from every object I can think of, but focus stays in the dialog.

    If the user must click back in the document, so be it. I got this bit of info from RibbonX for Dummies... and I wondered if it might not be too good to be true. The code seemed to refer to Icons as a data type ("Dim DlgIcons as Icons"), and I can't find any reference in Word 2007 to Icons as a data type.

    If the user makes use of the Insert Symbols dialog, the same situation prevails... click back in the document to continue typing. I don't think this presents a fresh hardship.

    Thanks,
    Richard

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

    Re: Take Focus on Click (Word 2007)

    I don't have Office 2007, so I can't tell why AppActivate causes an error, or whether "As Icons" is a valid declaration.

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Take Focus on Click (Word 2007)

    AppActivate "Microsoft Word" is given as an example in VBA Help for Office 2007, but it appears not to work if you're in Word. I tried Application.Activate and the dialog retained focus.

    Word 2007 is quirky. I have grown to like it very much, but I would call it half-baked. :-)

    Richard

Posting Permissions

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