XL2002: Error Message: Run-Time Error 1004: Unable to Set the LineStyle Property of the Border Class (277577)



The information in this article applies to:

  • Microsoft Excel 2002

This article was previously published under Q277577

SYMPTOMS

When you record and run a macro that creates a border around cells in a Microsoft Excel worksheet, you may receive the following error message:
Run-time error '1004'

Unable to set the LineStyle property of the Border class
However, if you click End in the error message, the border is successfully applied to the cells.

CAUSE

This behavior can occur when you attempt to record and then run a macro that places a border around cells in a single row, as in the following example:
  1. Open a new Excel workbook.
  2. On the View menu, point to Toolbars, and then click Borders.
  3. On the Tools menu, point to Macro, and then click Record New Macro.
  4. In the Record Macro dialog box, name the macro Macro1, and then click OK.
  5. On the Borders toolbar, click the arrow on the Draw Border icon.
  6. Click Draw Border Grid.
  7. Place the insertion point into the middle of cell C10, and then drag the insertion point to cell G10.

    Note that cells C10:G10 all have a border.
  8. On the Tools menu, point to Macro, and then click Stop Recording.
  9. Switch to Sheet2 in the workbook (click the Sheet2 tab at the bottom of the workbook window).
  10. On the Tools menu, point to Macro, and then click Macros.
  11. In the Macro name list, click Macro1, and then click Run.

    Note the run-time error message.
  12. In the error message, click End.

    Note that the macro creates the borders as expected.
You receive the error message because the macro records code (pertaining to the XlInsideHorizontal property) that is illegal for a bordered range with only one row.

RESOLUTION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: To resolve the issue, follow these steps:
  1. On the Tools menu, point to Macro, and then click Macros.
  2. In the Macro name list, click Macro1, and then click Edit.
  3. Delete the following code near the bottom of the module sheet:
    With Selection.Borders(xlInsideHorizontal)
          .LineStyle = xlContinuous
          .Weight = xlThin
          .ColorIndex = xlAutomatic
    End With
    					

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug kberrmsg kbpending KB277577