Share via

Sheet-related processing causes Excel VBA Userform to stop processing Tab/Enter

Anonymous
2014-03-22T15:22:06+00:00

This is a distilled form of a problem I'm having with a real application. Under certain circumstances, the initialization/activation code of a userform might result in the form losing its ability to correctly process tabs and enters: rather than switching between controls, these keys are passed to the controls themselves (even if they have TabKeyBehavior set to False). The simplest way I've found to systematically reproduce the problem is by having this at activation time:

Private Sub Userform_Activate() Application.DisplayDocumentInformationPanel = True End Sub

which seemingly causes Excel to "half-steal" the focus from the userform, so to say: the userform remains focused but tab/enter processing fails. The problem immediately goes away by switching to some external app and getting back to Excel (pressing ALT+TAB twice, for instance.)

Steps to reproduce the problem:

  1. Download tabnotworking.xslm.
  2. Open tabnotworking.xslm.
  3. Enable macros.
  4. Click on the "Launch UserForm1" button.
  5. UserForm1 is displayed and the textboxes accept input from the user, but tab/enter does not work as expected.
  6. Press ALT+TAB twice or click on some external app and get back to the form: now tab processing works OK.
  7. Once tab/enter processing has been restored, further usage of the form, including relaunching it, seems to work OK (most of the time). To reliably reproduce the problem again, close the book and start from step 2.

There are numerous references on the Internet to problems with tab processing seemingly related to this one, like for instance:

"VBA Form TabKeyBehavior = False is not working"

but no actual solution. Any clue on what's happening and how it could be solved? Thank you,

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2014-03-23T09:39:50+00:00

    Thanks for the answer, but I can't have my form show as modal.

    The issue really is: under certain circumstances (the example is a particularly simple way to reproduce them) userforms retain the focus but their associated controls don't receive KeyDown/KeyUp events, even though they're consuming user input!This looks to me like a VBA runtime bug.

    Was this answer helpful?

    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2014-03-23T03:37:49+00:00

    I am not sure that I really understand the issue, but try using the following

    Sub LaunchUserForm1()

    UserForm1.Show vbModeless

    End Sub

    Was this answer helpful?

    0 comments No comments