Drop-Down List Detached From ComboBox - Excel VBA - vba

The drop down list of a ActiveX ComboBox detaches whenever I scroll down the page. How
can I fix it so it won't move?
Here's the VBA code designated for the comboBox.
Private Sub ComboBox1_Change()
ComboBox1.ListFillRange = "DropDownList"
Me.ComboBox1.DropDown
End Sub

If you switch out your ComboBox to the one from the Forms toolbar, then it collapses the list as soon as you start scrolling. I think the "detaching" of the dropdown is the default behavior and I don't think you can influence that programmatically (as in here, too).
See this post on the different options for the comboboxes:
Run Macro When ComboBox is Clicked
Another option is to disable the mouse scroll, as in this post:
VBA Excel Combobox: drop-down list scrolling issue

Related

disabling all command button inside the option group/ rectangle box using ms access vba

I have a userform with lots of command button inside and outside the option group/ rectangle box. What I need is to disable all the command button inside the option group/ rectangle box and retain only the cbutton outside the option group/ rectangle as enabled.
Here is my code:
Dim ctrl As Control
'loop through all form controls
For Each ctrl In Me.Frame106.Controls
'if control is a Command Button
If TypeOf ctrl Is CommandButton Then
'set caption to null
ctrl.Enabled = false
End If
Next ctrl
I did some research and got the same code but the code is not working on my side. Thank you in advance for you help.
I have done some testing, and maybe an easy way of solving this would be to place your command buttons on a separate form, instead of a group box, and then use this form as a subform on you main form. You can make this look visually identical to a group box.

How to see if ComboBox is in DropDown State?

I have searched several forums but did not find answer for checking whether ComboBox is already DroppedDown via VBA code.
I have other code on Form_KeyDown events due to which anytime I press vbKeyDown it moves to next record. I need to check if ComboBox is DroppedDown then don't use other code and instead treat the default functionality of access where vbKeyDown will start scrolling through the items of ComboBox displayed in DropDown.
There is no such property, neither an event for OnDropDown or similar.
If the combobox has focus, you can force a dropdown using the DropDown method, but that's as close you can get.

Click/DoubleClick to open a Userform on Word

I was just creating a template on Word which uses content controls and I have a userform to help auto fill the data which is activated via a command key. You know how on excel VBA you can click a cell to make it refresh or open up a userform, or perform a series of tasks. On Word, can you double or single click a Content Control per say and have a userform pop up?
I think it would be pretty neat to be able to do that, open for any ideas that I should try out.
Unlike Content Controls, ActiveX controls have Click and DoubleClick events. You can add an ActiveX control (e.g., a button or a label) and use its Click event to do whatever you want:
And then simply, use something like this:
Private Sub lblTest_Click()
MsgBox "You clicked on a label."
End Sub
Private Sub btnTest_Click()
MsgBox "You clicked on a button."
End Sub
Result:
Hope that helps.

Run macro by clicking away from any ActiveX textbox in a document

I'm looking for a VBA script that will run whenever I click away from any of ActiveX textboxes in the document. Another alternative would be to have it run whenever I click on any textbox (without clicking away).
How can it be done without assigning subs to each textbox individually?
Double click on your textbox and it will bring up the default method for that textbox, which in my testing is Textbox1_Change(). This method will run every time you type anything into the textbox.
You see two dropdown boxes at the top of the vba editor. Drop down on the one on the right and you'll see all the other available methods for the textbox, one of which is LostFocus which I reckon will suit your purposes. Clicking on that creates a sub that will execute every time the textbox loses focus. See how you go with that. Cheers

Excel - Display ComboBox DropDown by VBA

I need a workbook to display the Combobox List Dropdown when it opens.
The combobox in the Workbook is a form control, so a shape.
Cant seem to find the associated property.
If you are using ActiveX Controls then see the below, else if you are using Form Controls then replace them with ActiveX Controls if you want the drop down to happen via code. The below code will work for both ActiveX Controls in a Form as well as Worksheet. If the Control is on a worksheet then change ComboBox1.SetFocus to ComboBox1.Activate
Two ways I can think of...
Using a simple command
Tried And Tested
Private Sub CommandButton1_Click()
ComboBox1.DropDown
End Sub
Using Sendkeys. Sendkeys are unreliable if not used properly.
Tried And Tested
Private Sub CommandButton1_Click()
ComboBox1.SetFocus
SendKeys "%{Down}"
End Sub
SCREENSHOTS
I have had plenty of crashes with .dropdown but find some success with
the SendKeys...
I consider best
UserForm combo box is as Above by Siddharth Rout
ComboBox1.SetFocus
SendKeys "%{Down}"
for some Combo boxes on a worksheets
CB.DropDown Is enough
.. Just as well as they have no setfocus or activate