SOLVED

how to nudge a control located in a parent object (like a frame)

%3CLINGO-SUB%20id%3D%22lingo-sub-2323317%22%20slang%3D%22en-US%22%3Ehow%20to%20nudge%20a%20control%20located%20in%20a%20parent%20object%20(like%20a%20frame)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2323317%22%20slang%3D%22en-US%22%3E%3CP%3EI%20created%20a%20nudge%20command%20that%20moves%20the%20top%2Fleft%20properties%20of%20selected%20controls%20of%20a%20userform%20in%20a%20particular%20direction.%20now%20that%20I%20am%20using%20it%2C%20I%20see%20an%20issue%20with%20the%20command.%20Any%20parent%20controls%20(like%20frame%2C%20tab%20strip%2C%20multipage%20with%20imbedded%20controls)%20that%20have%20the%20focus%20are%20the%20ones%20that%20get%20nudged%2C%20even%20if%20there%20are%20selected%20controls%20in%20that%20parent%20object.%20how%20can%20I%20gain%20access%20to%20the%20controls%20i%3CSPAN%3Enside%26nbsp%3B%20of%20a%20parent%20object%3F%20below%20is%20the%20three%20line%20procedure%20that%20moves%20the%20control.%20anyone%20with%20userform.designer%20knowledge%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%20%20%20%20For%20Each%20ctl%20In%20Workbooks(SelectedWb).VBProject.VBComponents(CompName).Designer.Selected%0A%20%20%20%20%20%20%20%20ctl.Left%20%3D%20ctl.Left%20%2B%20(DistanceInPixels%20%2F%202)%0A%20%20%20%20Next%20ctl%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2323317%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2326601%22%20slang%3D%22en-US%22%3ERe%3A%20how%20to%20nudge%20a%20control%20located%20in%20a%20parent%20object%20(like%20a%20frame)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2326601%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F379214%22%20target%3D%22_blank%22%3E%40DanMcG%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Egot%20this%20to%20work%20with%20Frames%20but%20not%20the%20multipage%20by%20doing%20the%20following%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%20%20%20%20For%20Each%20ctl%20In%20Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Selected%0A%20%20%20%20%20%20%20%20Debug.Print%20Left(ctl.Name%2C%209)%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20If%20Left(ctl.Name%2C%205)%20%3D%20%22Frame%22%20Or%20_%0A%20%20%20%20%20%20%20%20%20%20%20Left(ctl.Name%2C%203)%20%3D%20%22frm%22%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20For%20Each%20ctl2%20In%20Workbooks(activeWb).VBProject.VBComponents(preserveName).Designer.Controls(ctl.Name).Selected%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20parentCount%20%3D%20parentCount%20%2B%201%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'Debug.Print%20ctl2.Name%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20If%20parentCount%20%26gt%3B%200%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ctl2.Left%20%3D%20ctl2.Left%20%2B%20(lngDistanceInPixels%20%2F%202)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20%20%20%20%20Next%20ctl2%0A%20%20%20%20%20%20%20%20ElseIf%20Left(ctl.Name%2C%209)%20%3D%20%22Multipage%22%20Or%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Left(ctl.Name%2C%203)%20%3D%20%22mpg%22%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'do%20nothing%20yet%20as%20need%20to%20find%20out%20how%20to%20move%20the%20child%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20If%20parentCount%20%3D%200%20Then%20ctl.Left%20%3D%20ctl.Left%20%2B%20(lngDistanceInPixels%20%2F%202)%0A%20%20%20%20Next%20ctl%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Esince%20the%20multipage%20acts%20differently%20than%20a%20frame%2C%20how%20can%20i%20make%20it%20nudge%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

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

 

 

 

2 Replies

@DanMcG 

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?

best response confirmed by DanMcG (Occasional Contributor)
Solution

@DanMcG 

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