PDA

View Full Version : [SOLVED:] Take Focus Away From UserForm After Initializing It



zoom38
01-29-2024, 08:50 PM
Hello, I have a UF with a ComboBox on it. After its created (initialized) I want the focus to immediately go to a cell without clicking on it. So far the focus remains on the UF ComboBox until the UF change event is activated by using

AppActivate ThisWorkbook.Windows(1).Caption

It will also change focus if I click on a cell or use the up/down arrow keys. I've tried the following both in the UF initialize sub and the standard module where the sub that "shows" the UF is, with no success:



Application.SendKeys ("{ESC}")
AppActivate ("Microsoft Excel") - Fails completely
AppActivate ThisWorkbook.Windows(1).Caption
AppActivate ActiveWorkbook.Windows(1).Caption
AppActivate ThisWorkbook.Windows(1).Caption = True
AppActivate ActiveWorkbook.Windows(1).Caption = True
Range("B7").Activate


I've attached a sample workbook for reference.
Gary

Aflatoon
01-30-2024, 03:47 AM
The initialize event occurs when the form is loaded and before it is shown. I'd suggest you add a routine in a normal module that activates the workbook as per your first line of code, then call that from the Initialize event using Application.OnTime

zoom38
01-30-2024, 08:01 AM
The initialize event occurs when the form is loaded and before it is shown. I'd suggest you add a routine in a normal module that activates the workbook as per your first line of code, then call that from the Initialize event using Application.OnTime

Fantastic, Aflatoon your recommendation works great. :yes

Thx
Gary