CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2014
    Posts
    6

    Toggle Buttons hides/unhides a table below it (word VBA mso 7)

    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
    Join Date
    Oct 2014
    Posts
    6

    Re: Toggle Buttons hides/unhides a table below it (word VBA mso 7)

    cool, got it working.
    Code:
    Sub ShowHideGoals1()
          With Selection
            .GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=3
            .Tables(1).Range.Select
        End With
        If ToggleButton112.Value = True Then
            With Selection.Font
                .Hidden = True
            End With
            With ActiveWindow.View
                .ShowHiddenText = False
                .ShowAll = False
                .ShowParagraphs = False
            End With
        Else
            With Selection.Font
                .Hidden = False
            End With
            With ActiveWindow.View
                .ShowHiddenText = True
                .ShowAll = True
                .ShowParagraphs = True
            End With
            With Selection
                .Collapse direction:=wdCollapseStart
                .MoveLeft unit:=wdCharacter, Count:=1
                
            End With
            
        With ActiveWindow.View
            .ShowParagraphs = False
            .ShowAll = False
        End With
            
        End If
        
    End Sub
    All good, thanks

  3. #3
    Join Date
    Oct 2014
    Posts
    6

    Re: Toggle Buttons hides/unhides a table below it (word VBA mso 7)

    Now I have the problem that when I have both tables hidden, and I click to unhide the first table (togglebutton11), it unhides both tables.. I'm not sure why, but it must have both tables selected for some reason.

    Code:
    'initiates client info hide
    Sub ToggleButton11_Change()
    Call ShowHideGoals2
    End Sub
    
    'initiates family info info hide
    Sub ToggleButton112_Change()
    Call ShowHideGoals1
    End Sub
    
    
    
    '''' hide client info based off toggle button
    Sub ShowHideGoals2()
          With Selection
            .GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=2
            .Tables(1).Range.Select
        End With
        If ToggleButton11.Value = True Then
            With Selection.Font
                .Hidden = True
            End With
            With ActiveWindow.View
                .ShowHiddenText = False
                .ShowAll = False
                .ShowParagraphs = False
            End With
        Else
            With Selection.Font
                .Hidden = False
            End With
            With ActiveWindow.View
                .ShowHiddenText = True
                .ShowAll = True
                .ShowParagraphs = True
            End With
            With Selection
                .Collapse direction:=wdCollapseStart
                .MoveLeft unit:=wdCharacter, Count:=1
            End With
        With ActiveWindow.View
            .ShowParagraphs = False
            .ShowAll = False
        End With
        End If
    End Sub
    
    
    '''' hide family table based off toggle button
    Sub ShowHideGoals1()
          With Selection
            .GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=3
             .Tables(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
            
        With ActiveWindow.View
            .ShowParagraphs = False
            .ShowAll = False
        End With
            
        End If
        
    End Sub

  4. #4
    Join Date
    Oct 2014
    Posts
    6

    Re: Toggle Buttons hides/unhides a table below it (word VBA mso 7)

    Is there a way to just hide a table under particular words?? This table count isn't very efficient. So if i could just hide a table under the title "blah" would be good

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Toggle Buttons hides/unhides a table below it (word VBA mso 7)

    Just set up a few flags, and use them instead. Shouldn't be too difficult to keep things apart. Could use =1 =2 =3 or BOOLEAN
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured