PDA

View Full Version : [SOLVED:] Multiple Frames on A Excel UserForm and switch the visibility



simora
04-23-2018, 12:57 AM
How can I place one frame on top of another and switch the visibility to show one Frame or the other.

I have an Excel Userform with two frames, and I want to place one directly on top of the other, however, Frame 2 does not become Visible even after I execute the following code.



Private Sub CommandButton2_Click()

Frame1.Visible = False
Frame2.Visible = True


Any ideas how to make this work.

Does Z Order work with VBA to control frames ? If so How?

Thanks

Bob Phillips
04-23-2018, 02:22 AM
Are ou sure that both frames are separate, one is not within the other? That is the only way I could see what you get.

simora
04-23-2018, 03:20 AM
Frame2 is NOT totally inside frame1. I've done this before, but not getting this result.

Bob Phillips
04-23-2018, 05:22 AM
Can you post the workbook, as I said it works for me when the frames are not within each other.

p45cal
04-23-2018, 05:51 AM
I think it may hinge around how you're placing the frames on the userform.
If you use your mouse, it seems that it's inevitable that one frame lies within the other.
If you start with the two frames side by side and not overlapping at all, they'll both have the userform as a parent.
Then, if instead of using the mouse, you adjust the top and left in the Properties window pane of the VBE by typing in numbers (pressing Enter each time to make it stick), both frames' parent remain the same (the userform). Use the mouse and one frame will be the parent of the other. I don't know how to avoid this when using just the mouse.
In the attached are two userforms, seemingly identical, one behaves as you describe, the other behaves as you want. There's a bit of code which reports the situation both as msgboxes and in the Immediate pane (debug.print statements) when you click the button on the form to change the frames' visibilities. Both forms are modeless, but that shouldn't matter.

Paul_Hossler
04-23-2018, 08:09 AM
Building on p45cal's approach

For development, the UF is larger to add more real estate to make sure the frames are not inside the other





Option Explicit

Private Sub CommandButton1_Click()
UserForm1.Frame1.Visible = Not UserForm1.Frame1.Visible
UserForm1.Frame2.Visible = Not UserForm1.Frame2.Visible
End Sub

Private Sub UserForm_Initialize()
With Me
'set to production size (not development size)
.Height = 175
.Width = 200
.Frame1.Visible = True
With .Frame2
.Visible = False
.Top = UserForm1.Frame1.Top
.Left = UserForm1.Frame1.Left
.Height = UserForm1.Frame1.Height
.Width = UserForm1.Frame1.Width
End With
End With

End Sub

simora
04-27-2018, 02:32 PM
Thanks Guys.

Was travelling for a few days & still Sleep Deprived !. I used Paul_Hossler (http://www.vbaexpress.com/forum/member.php?9803-Paul_Hossler)'s approach.
Maybe easier to manipulate multiple frames like that.

p45cal (http://www.vbaexpress.com/forum/member.php?3494-p45cal) 's approach as explained may also have some other uses & I will be re-visiting it.
Great ideas.



Thanks All.