VBA FORM, EXPANDING FORM SIZE, BASED ON VISIBILITY OF FRAME

VBA FORM, EXPANDING FORM SIZE, BASED ON VISIBILITY OF FRAME

Anonymous
Not applicable
865 Views
2 Replies
Message 1 of 3

VBA FORM, EXPANDING FORM SIZE, BASED ON VISIBILITY OF FRAME

Anonymous
Not applicable

Good morning all.

I've built a user form in vba, and was wanting to have the form's overall size change, based on the visibility of frames which I'm placing on the form.

I.e., if I select a check box, an expanded version of the form is turned on, allowing secondary, and tertiary elements to be shown. However, when the base elements are active, I want the form to be a smaller/base size.

 

Is this possible? 

 

TYIA

0 Likes
Accepted solutions (1)
866 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

You can change UserForm's size (Height/Width), Location(Left/Top) as needed in code.

 

Here is a very simplified case: an UserForm with a CheckBox on it. When the CheckBox is checked by user, the form's width expand, unchecked - shrinks:

 

Option Explicit

Private Const mWidth As Integer = 400

Private Sub CheckBox1_Click()
    
    If CheckBox1.Value Then
        Me.width = mWidth * 2
    Else
        Me.width = mWidth
    End If
End Sub


Private Sub UserForm_Initialize()

    Me.width = mWidth

End Sub

So, you can place the secondary controls on the form expanded side, obviously.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

Anonymous
Not applicable

@norman.yuan wrote:

You can change UserForm's size (Height/Width), Location(Left/Top) as needed in code.

 

Here is a very simplified case: an UserForm with a CheckBox on it. When the CheckBox is checked by user, the form's width expand, unchecked - shrinks:

 

Option Explicit

Private Const mWidth As Integer = 400

Private Sub CheckBox1_Click()
    
    If CheckBox1.Value Then
        Me.width = mWidth * 2
    Else
        Me.width = mWidth
    End If
End Sub


Private Sub UserForm_Initialize()

    Me.width = mWidth

End Sub

So, you can place the secondary controls on the form expanded side, obviously.


Good morning.

 It works EXACTLY as I need too. 

 Yes, the expansion of more controls is my purpose. One discussion I'd read on the web was that I could house secondary/tertiary controls within frames, and then turn the respective frame's visibility state on and off, based on the checkbox. But as I began working through it, I realized that I'd need to keep a constant width form. It made far more sense to change the width of the form as the need expanded. So.... this is a perfect answer to the frame/width issue. 

Suuuwwwweeeet!

Thank you.

😄

0 Likes