Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 23 of 23

Thread: Help in Tab in user form

  1. #21
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    [VBA]Private Sub TabStrip1_Click(ByVal Index As Long)
    Dim cTabs As Integer
    With Me.TabStrip1
    cTabs = .Tabs.Count

    If Index = cTabs - 1 Then
    If cTabs > 20 Then
    .Value = cTabs - 2
    MsgBox Prompt:="You cannot open anymore tabs.", Title:="Maximum number of tabs has been reached", Buttons:=vbExclamation
    Else
    .Tabs.Add "", "page " & cTabs, cTabs - 1
    .Value = cTabs - 1
    End If
    End If
    End With

    End Sub
    [/VBA]
    Glen

  2. #22
    VBAX Regular
    Joined
    Feb 2007
    Posts
    68
    Location
    Hi moa,
    Thanks and any idea to add a right click menu to a tab that contains (1) Add tabs and (2) close tab (or close all tabs) ?
    and is it possible to add some pictures to the caption of the tab??

    Thanks
    Dan

  3. #23
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why don't you state the whole requirement at the start rather than drip-feeding it, changing everything we have done along the way, and wasting time!

    [vba]


    Private Sub Userform_Activate()
    'Remove any old instance of MyPopUp
    On Error Resume Next
    CommandBars("MyPopUp").Delete
    On Error GoTo 0

    With CommandBars.Add(Name:="MyPopUp", Position:=msoBarPopup)
    With .Controls.Add(Type:=msoControlButton)
    .OnAction = "AddTab"
    .Caption = "Add Tab"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .OnAction = "RemoveTab"
    .Caption = "Remove Tab"
    End With
    End With
    End Sub

    Private Sub TabStrip1_MouseUp(ByVal Index As Long, ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If Button = 2 Then
    Application.CommandBars("MyPopUp").ShowPopup
    End If
    End Sub
    [/vba]

    and in a standard code module

    [vba]

    Public Sub AddTab()
    Dim cTabs As Long
    With UserForm1.TabStrip1
    cTabs = .Tabs.Count

    If cTabs > 20 Then
    .Value = cTabs - 2
    MsgBox Prompt:="You cannot open more tabs", Title:="Maximum number of tabs has been reached", Buttons:=vbExclamation
    Else
    .Tabs.Add "", "page " & cTabs, cTabs - 1
    .Value = cTabs - 1
    End If
    End With
    End Sub

    Public Sub RemoveTab()
    Dim cTabs As Long
    With UserForm1.TabStrip1
    cTabs = .Tabs.Count

    If cTabs = 1 Then
    .Value = 0
    MsgBox Prompt:="You must have at least one tab", Title:="Minimum number of tabs has been reached", Buttons:=vbExclamation
    Else
    .Tabs.Remove .Value
    ' .Value = cTabs - 1
    End If
    End With
    End Sub
    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •