SOLVED

Can I programmatically change properties of selected userform controls when I am designing the form?

Brass Contributor

I have created code to add 4 new commands to a context menu (MSForms Control) that is shown when I right click on selected controls in a userform. Basically I want to nudge the selected controls in a particular direction (up/down/left/right) a set number of pixels? I realize that the Selection command is only for Excel proper and not VBE. Is there a way of looping through the 'selection set' of selected controls and modify the Top/Left properties when I am constructing the userform?

3 Replies
best response confirmed by DanMcG (Brass Contributor)
Solution

@DanMcG

I've determined that this cannot be done, so how do I close the question? 

@DanMcG 

ThisWorkbook.VBProject.VBComponents("UserForm1").designer.controls("ComboBox1").left = 0

and/or

ThisWorkbook.VBProject.VBComponents("UserForm1").designer.controls("ComboBox1").top = 0

 

note that ThisWorkbook.VBProject.VBComponents("UserForm1").designer properties and methods are hidden and there is no intellisense available

 

@ExcelHCFUser 

 

This can be done by accessing the .Designer property of the selected vbcomponent. Below will move the selected controls a specific direction a number of pixels.

Sub nudgeHor(distanceInPixels As Long)
    Dim ctl    As Control
    For Each ctl In ThisWorkbook.VBProject.VBComponents(Application.VBE.SelectedVBComponent.Name).Designer.Selected
        ctl.Left = ctl.Left + distanceInPixels
    Next ctl
End Sub
Sub nudgeVer(distanceInPixels As Long)
    Dim ctl    As Control
    For Each ctl In ThisWorkbook.VBProject.VBComponents(Application.VBE.SelectedVBComponent.Name).Designer.Selected
        ctl.Top = ctl.Top + distanceInPixels
    Next ctl
End Sub
1 best response

Accepted Solutions
best response confirmed by DanMcG (Brass Contributor)
Solution

@DanMcG

I've determined that this cannot be done, so how do I close the question? 

View solution in original post