Results 1 to 2 of 2

Thread: Toggle Buttons hides/unhides a table below it

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    3

    Toggle Buttons hides/unhides a table below it

    Hey all

    I am trying to make a toggle button next to the title of the table, in this case "Family Information" hide and unhide the table below. So basically it toggles if that table is hidden or viewed, and the toggle button caption is "+ / -"

    I want the code to recognise the title text above the table, so that the one table below that text is what is hidden or unhidden. This is what I have so far but it's not working. I think it's the with selection part that is not correct.

    Code:
    Sub ToggleButton112_Change()
    Call ShowHideGoals1
    End Sub
    
    '''' Start hiding family table based off toggle button
    
    Sub ShowHideGoals1()
          With Selection
            .GoTo What:=wdGoToTable, Which:=wdGoToFirst, _
            Count:=2, Name:="Family Information"
            .Tables(1).Cell(1, 1).Range.Select
        End With
        If ToggleButton112.Value = True Then
            With Selection.Font
                .Hidden = True
            End With
            With ActiveWindow.View
                .ShowHiddenText = False
                .ShowAll = False
            End With
        Else
            With Selection.Font
                .Hidden = False
            End With
            With ActiveWindow.View
                .ShowHiddenText = True
                .ShowAll = True
            End With
            With Selection
                .Collapse direction:=wdCollapseStart
                .MoveLeft unit:=wdCharacter, Count:=1
            End With
            
        End If
    End Sub

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Toggle Buttons hides/unhides a table below it

    you can test this to see if it works for you
    this assumes that each table is a named range and the button is placed over part of table
    Code:
    Private Sub ToggleButton1_Click()
    For Each n In ThisWorkbook.Names
        If n.RefersToRange.Parent.Name = ToggleButton1.Parent.Name Then
        If Not Intersect(n.RefersToRange, ToggleButton1.TopLeftCell) Is Nothing Then
            With Range(n.Name)
                If .Font.Color = 0 Then
                    .Font.Color = vbWhite
                    Else
                    .Font.Color = 0
                End If
            End With
        End If
        End If
    Next
    End Sub
    of course this only works for black font to hidden, but could easily be modified to for any colour font, but mixed font colours would be more difficult as each colour would have to be remembered, especially if cells could contain mixed colour text
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width