Hide MS-Word Table Row Based Upon Selection

Joined
Dec 10, 2013
Messages
2
Reaction score
0
Hello,

I have six forms that I would like to combine into one. I want the user to be able to select the applicable form name from the MS-Word drop-down list, and have the appropriate table row open up, while all the other rows are closed.

I found the below code during an internet search BUT it only works for three(3) rows and I need it to work for six(6) rows. I tried modifying the code for the additional lines I need but I can't get it to work properly.

I am new to using VBA and becoming frustrated. Can someone please help me?

Thank you.
--------------------------------
Option Explicit
Const OPA = "AWARD OF BID"
Const OPB = "CONTRACT"
Const OPC = "FINAL"
Private Sub Document_Open()
ComboBox1.List = Array(OPA, OPB, OPC)
End Sub

Private Sub ComboBox1_Change()
If ComboBox1.Value = OPA Then
With ActiveDocument.Tables(1).Rows(1)
.HeightRule = wdRowHeightAuto
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
End With
With ActiveDocument.Tables(1).Rows(2)
.HeightRule = wdRowHeightExactly
.Height = ".5"
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
End With
With ActiveDocument.Tables(1).Rows(3)
.HeightRule = wdRowHeightExactly
.Height = ".5"
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
End With
ElseIf ComboBox1.Value = OPB Then
With ActiveDocument.Tables(1).Rows(1)
.HeightRule = wdRowHeightExactly
.Height = ".5"
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
End With
With ActiveDocument.Tables(1).Rows(2)
.HeightRule = wdRowHeightAuto
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
End With
With ActiveDocument.Tables(1).Rows(3)
.HeightRule = wdRowHeightExactly
.Height = ".5"
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
End With
ElseIf ComboBox1.Value = OPC Then
With ActiveDocument.Tables(1).Rows(1)
.HeightRule = wdRowHeightExactly
.Height = ".5"
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
End With
With ActiveDocument.Tables(1).Rows(2)
.HeightRule = wdRowHeightExactly
.Height = ".5"
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
End With
With ActiveDocument.Tables(1).Rows(3)
.HeightRule = wdRowHeightAuto
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
End With
End If

lbl_Exit:
Exit Sub
End Sub
 
Joined
Dec 10, 2013
Messages
2
Reaction score
0
Resolved

I figured out what I was doing wrong, and now my table works like a charm!
 

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