J
JuanManuel
I have a document with many tables. I want to have a button or checkbox or
radiobutton located in the upper-right cell of each table so that upon
clicking on it, all of the rows within the table hide, except for the first
row.
If the the rows are hidden, another click of the event-trigger will unhide
them.
So far, I have something like this:
Private Sub BtnHide1_Click()
Dim TableNo As Integer
TableNo = 1
Call CountTablesRowsParas(TableNo)
End Sub
'Identify which table is at stake
Sub CountTablesRowsParas(WhichTable As Integer)
Dim oDoc As Document
Dim oRange As Range
Dim nTables As Long
Dim nRows As Long
Set oDoc = ActiveDocument
Set oRange = oDoc.Range
nTables = oRange.Tables.Count
MsgBox "This document has " & nTables & " table(s)."
If nTables <= 0 Then
MsgBox ("This document does not have tables. Please use the Headline
View of Word to hide lines of text")
Exit Sub
ElseIf nTables > 0 Then
nRows = oRange.Tables(WhichTable).Rows.Count
Call HideRows(nRows)
MsgBox "Table number " & WhichTable & " has " & nRows & " row(s)."
End If
'counting the rows of the table at stake and calling the hide sub
Sub HideRows(howmany As Long)
Dim i As Long
For i = 2 To howmany
ActiveDocument.Tables(1).Rows(i).Range.Font.Hidden = True
Next
End Sub
'executing the hide procedure
What I would like to do is to modify the first sub called "Private Sub
BtnHide1_Click()" so that I don't have to write as many of these as there are
tables in the document.
Is there a way to, upon clicking the event-trigger located in the
upper-right cell of a particular table, identify which table am I on and send
this parameter to "Sub CountTablesRowsParas(WhichTable As Integer)".?
Thank you,
Juan
radiobutton located in the upper-right cell of each table so that upon
clicking on it, all of the rows within the table hide, except for the first
row.
If the the rows are hidden, another click of the event-trigger will unhide
them.
So far, I have something like this:
Private Sub BtnHide1_Click()
Dim TableNo As Integer
TableNo = 1
Call CountTablesRowsParas(TableNo)
End Sub
'Identify which table is at stake
Sub CountTablesRowsParas(WhichTable As Integer)
Dim oDoc As Document
Dim oRange As Range
Dim nTables As Long
Dim nRows As Long
Set oDoc = ActiveDocument
Set oRange = oDoc.Range
nTables = oRange.Tables.Count
MsgBox "This document has " & nTables & " table(s)."
If nTables <= 0 Then
MsgBox ("This document does not have tables. Please use the Headline
View of Word to hide lines of text")
Exit Sub
ElseIf nTables > 0 Then
nRows = oRange.Tables(WhichTable).Rows.Count
Call HideRows(nRows)
MsgBox "Table number " & WhichTable & " has " & nRows & " row(s)."
End If
'counting the rows of the table at stake and calling the hide sub
Sub HideRows(howmany As Long)
Dim i As Long
For i = 2 To howmany
ActiveDocument.Tables(1).Rows(i).Range.Font.Hidden = True
Next
End Sub
'executing the hide procedure
What I would like to do is to modify the first sub called "Private Sub
BtnHide1_Click()" so that I don't have to write as many of these as there are
tables in the document.
Is there a way to, upon clicking the event-trigger located in the
upper-right cell of a particular table, identify which table am I on and send
this parameter to "Sub CountTablesRowsParas(WhichTable As Integer)".?
Thank you,
Juan