How to fix object error when creating border in excel spreadsheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MarkBStewart
    New Member
    • May 2010
    • 20

    How to fix object error when creating border in excel spreadsheet

    I am trying to create borders in an excel spreadsheet programaticaly using VBA. I am getting an object error on line 2 Selection.Borde rs(xlDiagonalDo wn...


    This is my code:

    Code:
     xlWS.Range("F2:J410").Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlContinuous
        Selection.Borders(xlDiagonalUp).LineStyle = xlContinuous
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .ColorIndex = 0
        End With
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Try giving actual values, instead of constants:

    Selection.Borde rs(5).LineStyle = -4142
    Selection.Borde rs(6).LineStyle = -4142

    Regards
    Veena

    Comment

    • MarkBStewart
      New Member
      • May 2010
      • 20

      #3
      No go. I am still getting "ActiveX Componenet Cannot Create Object" message. Any ideas? Should I somehow be refering to the worksheet object in the Selection statement?

      Comment

      Working...