1

So I have a multipage where I want the same button to show on both pages. I could place it outside but the border from the multipage is so ugly so I tried to place everything on the pages. Unfortunately you can't name the items (such as the combobox) with the same name. Is there a workaround to remove the borders and just show the page names or have the same name on the item on two pages?

enter image description here

enter image description here

Fredrik
  • 477
  • 4
  • 22
  • I am not that good in userforms but couldn't you use a name with suffix, and the suffix represents the page nr.? Meaning like DoItButton1 and DoItButton5 bc on page 1 and 5 is the same button and you reference it like "DoItButton"+pagenr? – Kajkrow Jul 02 '18 at 05:53
  • So your multipage only has 2 pages? Depends on your need, sometimes a TabStrip is better especially when you have "Shared" controls. – PatricK Jul 02 '18 at 06:07
  • Added two pictures to display a little more. @Kajkrow I'm currently trying to do that but it quickly becomes complicated as it is used quite much. – Fredrik Jul 02 '18 at 06:21
  • @PatricK Tried using that but didnt seem to get it to work, Currently I'm working to copy paste the items on the right to another page. – Fredrik Jul 02 '18 at 06:22
  • 1
    To use the TabStrip with easier hide/show relevant Controls, put the controls for each page into different invisible frame (either by default or at UserForm Initialize with **No Caption**, `SpecialEffect = fmSpecialEffectFlat`). Then on `TabStrip1_Change` event, change the Visible state of the frames and place them to desired Top and Left. – PatricK Jul 02 '18 at 06:51
  • @PatricK But is there any way when editing to prevent them from overlapping? – Fredrik Jul 02 '18 at 07:17
  • You can create a big UserForm with those frames at bottom and side by side, then at `UserForm_Initialize`, move them into desired Top, Left position, change Visible state according to the Active Tab, and change the Userform Width, Height to smaller. – PatricK Jul 02 '18 at 07:21
  • You might find some use of [this answer from Siddharth Rout](https://stackoverflow.com/a/10822863/9663006) which shows how to group relevant controls and move them when you change pages. I feel that the answer may not directly show you what you want but should give you the correct way of thinking to find a solution to your question. Otherwise, you might want to, as suggested above by @PatricK use a Tab Strip instead. You could set to the `TabStrip1_Change` event `If Me.Tabstrip1.value = 1 Then...Do some things...End If` which will "Do some things" if `Tab2` is selected (tabs are Zero-Indexed). – Samuel Everson Jul 03 '18 at 04:55

1 Answers1

1

Had some fun with this goal.

Consider this UserForm in Editor with TabStrip, 2 frames and some other controls.
Frames are named from Frame0, Frame1, etc.
Assuming the Frame0 is the location reference and first to display when UserForm is displayed, code below will be what you want.
UserForm Editor

Code:

Option Explicit

Private Sub TabStrip1_Change()
    Dim i As Long, lActiveTabIndex As Long
    lActiveTabIndex = Me.TabStrip1.Value
    For i = 0 To Me.TabStrip1.Tabs.Count - 1
        Me.Controls("Frame" & i).Visible = (i = lActiveTabIndex)
    Next i
End Sub

Private Sub UserForm_Initialize()
    Dim i As Long
    With Me
        .Height = 288 ' Adjust to your desired height
        ' Align all FrameX top/left to same as Frame0, delete Caption and SpecialEffect
        For i = 0 To Me.TabStrip1.Tabs.Count - 1
            With Me.Controls("Frame" & i)
                .Top = Me.Frame0.Top
                .Left = Me.Frame0.Left
                .Caption = ""
                .SpecialEffect = fmSpecialEffectFlat
            End With
        Next i
    End With
    ' Ensure frame for first tab is displayed
    TabStrip1_Change
End Sub

Userform first load (didn't save screenshot, neither the workbook, sorry).

Next tab clicked:
next tab clicked

PatricK
  • 6,375
  • 1
  • 21
  • 25