Consulting

Results 1 to 2 of 2

Thread: Toggle button to hide rows in two different tables

  1. #1

    Question Toggle button to hide rows in two different tables

    Hello. I am quite new to VBA and would really appreciate some help.

    I have successfully added a toggle button which shows or hides a table table row when it is clicked.
    The trouble I'm having is that I need it to do the same thing in a different table at the same time.
    ie. one button click hides a row in table 8 and also in table 10.

    I am using Word 2010. This is my code so far:
    Private Sub ToggleButton1_Click()
    With ActiveDocument.Tables(8).Rows(2)
    If .HeightRule = wdRowHeightExactly Then
    .HeightRule = wdRowHeightAuto
    ToggleButton1.Caption = "Yes"
    .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
    .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
    .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
    Else
    ToggleButton1.Caption = "No"
    .HeightRule = wdRowHeightExactly
    .Height = ".5"
    .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
    .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
    .Borders(wdBorderRight).LineStyle = wdLineStyleNone
    End If
    End With
    lbl_Exit:
    Exit Sub
    End Sub

    Thanks in advance for your time.
    Last edited by Shimarisu; 11-10-2014 at 06:23 AM.

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    At its simplest, you simply replicate the code you have for Table 8 and point it to Table 10:
    Private Sub ToggleButton1_Click()
    With ActiveDocument.Tables(8).Rows(2)
      If .HeightRule = wdRowHeightExactly Then
        .HeightRule = wdRowHeightAuto
        ToggleButton1.Caption = "Yes"
        .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
        .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
        .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
     Else
       ToggleButton1.Caption = "No"
      .HeightRule = wdRowHeightExactly
      .Height = ".5"
      .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
      .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
      .Borders(wdBorderRight).LineStyle = wdLineStyleNone
      End If
    End With
    With ActiveDocument.Tables(10).Rows(2)
      If .HeightRule = wdRowHeightExactly Then
        .HeightRule = wdRowHeightAuto
        .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
        .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
        .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
     Else
      .HeightRule = wdRowHeightExactly
      .Height = ".5"
      .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
      .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
      .Borders(wdBorderRight).LineStyle = wdLineStyleNone
      End If
    End With
    End Sub
    PS: When posting code, please use the code tags, indicated by the # symbol on the posting menu.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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