none
run-time error '5941.: RRS feed

  • Question

  • I am having trouble with this and as i am new to all this i need to reach out for help.

    I get this error for "With ActiveDocument.Tables(1).Rows(14)" on both lines in the code. any ideas how to fix it please.

    Full code below

    Option Explicit
    Const Over = ">£30k"
    Const Under = "<£30k"

    Private Sub Document_Open()
    ComboBox1.List = Array(Over, Under)
    End Sub

    Private Sub ComboBox1_Change()
    Application.Templates.LoadBuildingBlocks
        If ComboBox1.Value = Over Then
            With ActiveDocument.Tables(1).Rows(1)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderTop).LineStyle = wdLineStyleSingle
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
            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 = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(4)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(5)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(6)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(7)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(8)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(9)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(10)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(11)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(12)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(13)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(14)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(15)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(16)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(17)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
        ElseIf ComboBox1.Value = Under 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 = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(4)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(5)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(6)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(7)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(8)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(9)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(10)
            .HeightRule = wdRowHeightExactly
            .Height = ".5"
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
             End With
            With ActiveDocument.Tables(1).Rows(11)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderTop).LineStyle = wdLineStyleSingle
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(12)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(13)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(14)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(15)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(16)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
            With ActiveDocument.Tables(1).Rows(17)
            .HeightRule = wdRowHeightAuto
            .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
            .Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
            .Borders(wdBorderRight).LineStyle = wdLineStyleSingle
             End With
        End If

    lbl_Exit:
      Exit Sub
    End Sub

    Wednesday, September 4, 2019 8:10 AM

All replies

  • Probably best to start with the basics.

    1. Is Table(1) definitely the table you need to access? (e.g. could there be another table, hidden or some such?)

    2. Does Table (1) definitely have at least 14 rows?


    Peter Jamieson

    Wednesday, September 4, 2019 9:31 AM