Forum Discussion
how to nudge a control located in a parent object (like a frame)
I created a nudge command that moves the top/left properties of selected controls of a userform in a particular direction. now that I am using it, I see an issue with the command. Any parent controls (like frame, tab strip, multipage with imbedded controls) that have the focus are the ones that get nudged, even if there are selected controls in that parent object. how can I gain access to the controls inside of a parent object? below is the three line procedure that moves the control. anyone with userform.designer knowledge?
For Each ctl In Workbooks(SelectedWb).VBProject.VBComponents(CompName).Designer.Selected
ctl.Left = ctl.Left + (DistanceInPixels / 2)
Next ctl
For Each ctl In Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Selected
If TypeName(ctl) = "Frame" Then
For Each ctl2 In Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Controls(ctl.Name).Selected
childCount = childCount + 1
ctl2.Left = ctl2.Left + (lngDistanceInPixels / 2)
Next ctl2
If childCount = 0 Then ctl.Left = ctl.Left + (lngDistanceInPixels / 2)
childCount = 0
ElseIf TypeName(ctl) = "MultiPage" Then
pageSelect = Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Controls(ctl.Name).Value
For Each ctl2 In Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Controls(ctl.Name).Pages(pageSelect).Selected
childCount = childCount + 1
ctl2.Left = ctl2.Left + (lngDistanceInPixels / 2)
Next ctl2
If childCount = 0 Then ctl.Left = ctl.Left + (lngDistanceInPixels / 2)
childCount = 0
ElseIf TypeName(ctl) = "TabStrip" Then
ctl.Left = ctl.Left + (lngDistanceInPixels / 2)
Else
ctl.Left = ctl.Left + (lngDistanceInPixels / 2)
End If
Next ctl
2 Replies
- DanMcGBrass Contributor
got this to work with Frames but not the multipage by doing the following:
For Each ctl In Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Selected Debug.Print Left(ctl.Name, 9) If Left(ctl.Name, 5) = "Frame" Or _ Left(ctl.Name, 3) = "frm" Then For Each ctl2 In Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Controls(ctl.Name).Selected parentCount = parentCount + 1 'Debug.Print ctl2.Name If parentCount > 0 Then ctl2.Left = ctl2.Left + (lngDistanceInPixels / 2) End If Next ctl2 ElseIf Left(ctl.Name, 9) = "Multipage" Or _ Left(ctl.Name, 3) = "mpg" Then 'do nothing yet as need to find out how to move the child End If If parentCount = 0 Then ctl.Left = ctl.Left + (lngDistanceInPixels / 2) Next ctl
since the multipage acts differently than a frame, how can i make it nudge?
- DanMcGBrass Contributor
For Each ctl In Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Selected
If TypeName(ctl) = "Frame" Then
For Each ctl2 In Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Controls(ctl.Name).Selected
childCount = childCount + 1
ctl2.Left = ctl2.Left + (lngDistanceInPixels / 2)
Next ctl2
If childCount = 0 Then ctl.Left = ctl.Left + (lngDistanceInPixels / 2)
childCount = 0
ElseIf TypeName(ctl) = "MultiPage" Then
pageSelect = Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Controls(ctl.Name).Value
For Each ctl2 In Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Controls(ctl.Name).Pages(pageSelect).Selected
childCount = childCount + 1
ctl2.Left = ctl2.Left + (lngDistanceInPixels / 2)
Next ctl2
If childCount = 0 Then ctl.Left = ctl.Left + (lngDistanceInPixels / 2)
childCount = 0
ElseIf TypeName(ctl) = "TabStrip" Then
ctl.Left = ctl.Left + (lngDistanceInPixels / 2)
Else
ctl.Left = ctl.Left + (lngDistanceInPixels / 2)
End If
Next ctl