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
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