expand or hide text using a macro and control button

N

newbei

Hi,

I have a large word document, which gets a little bit difficult to
read.
It has large amounts of tables with values mentioned below in the
table, some of these tables don’t have any values mentioned below but
need to have a title.


I want to create a document so that the display of certain
information
can be expanded or collapsed.


I found a wonderful article, which provides a sample here:
http://gregmaxey.mvps.org/Toggle_Data_Display.htm


But I am unable to replicate this in the word document I have. The
issues I have:


1.If I have more than two tables then the control to show/hide only
works for the first table and not the second table


2.How to add a macro to a control button. i.e.: if I define a control
button , and want certain macro runs when I press that button , how
to
link the macro with the control button.


Any help or pointers would be great


Regards,


Rajesh
 
D

Doug Robbins - Word MVP

Show us your adaptation of the code

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Hi,

I have a large word document, which gets a little bit difficult to
read.
It has large amounts of tables with values mentioned below in the
table, some of these tables don’t have any values mentioned below but
need to have a title.


I want to create a document so that the display of certain
information
can be expanded or collapsed.


I found a wonderful article, which provides a sample here:
http://gregmaxey.mvps.org/Toggle_Data_Display.htm


But I am unable to replicate this in the word document I have. The
issues I have:


1.If I have more than two tables then the control to show/hide only
works for the first table and not the second table


2.How to add a macro to a control button. i.e.: if I define a control
button , and want certain macro runs when I press that button , how
to
link the macro with the control button.


Any help or pointers would be great


Regards,


Rajesh
 
N

newbei

Hi Doug,

Thanks a ton for your reply.
I am using the below code picked up from the website i mentioned in
the link above.

It works fine for a single table entry , i would liek to do it for
multiple tables.
I.e i want to place the show or hide button on any table then on
pressing that be able to perform the macro.
I have no experience with macros or vb as such so dont know where to
being, a simple copy and paste doesnt do the job.

Option Explicit
Const pValue_1 = "Show"
Const pValue_2 = "Hide"
Sub CallShowHide()
ShowHide Selection.Bookmarks(1).Name
End Sub
Sub ShowHide(pVarName As String)
Dim pValue As String

On Error Resume Next
pValue = ActiveDocument.Variables(pVarName)
On Error GoTo 0
If pValue = "" Or pValue = pValue_2 Then
pValue = pValue_1
Else
pValue = pValue_2
End If
ActiveDocument.Variables(pVarName).Value = pValue
ActiveDocument.Fields.Update
End Sub
Sub CallViewHide()
With ActiveDocument.Tables(2).Rows(2)
If .HeightRule = wdRowHeightExactly Then
.HeightRule = wdRowHeightAuto
'ToggleButton1.Caption = "Hide"
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
Else
'ToggleButton1.Caption = "Show"
.HeightRule = wdRowHeightExactly
.Height = ".5"
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
End If
End With
End Sub


Looking forward to your inputs.

Rajesh
 
D

Doug Robbins - Word MVP

Declare a variable i

Dim i as Long

then replace

With ActiveDocument.Tables(2).Rows(2)
If .HeightRule = wdRowHeightExactly Then
.HeightRule = wdRowHeightAuto
'ToggleButton1.Caption = "Hide"
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
Else
'ToggleButton1.Caption = "Show"
.HeightRule = wdRowHeightExactly
.Height = ".5"
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
End If
End With

with

For i = 2 to ActiveDocument.Tables.Count
With ActiveDocument.Tables(i).Rows(2)
If .HeightRule = wdRowHeightExactly Then
.HeightRule = wdRowHeightAuto
'ToggleButton1.Caption = "Hide"
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
Else
'ToggleButton1.Caption = "Show"
.HeightRule = wdRowHeightExactly
.Height = ".5"
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
End If
End With
Next i

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top