This article was previously published under Q277577
This article has been archived. It is offered "as is" and will no longer be updated.
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.
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:
Open a new Excel workbook.
On the View menu, point to Toolbars, and then click Borders.
On the Tools menu, point to Macro, and then click Record New Macro.
In the Record Macro dialog box, name the macro Macro1, and then click OK.
On the Borders toolbar, click the arrow on the Draw Border icon.
Click Draw Border Grid.
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.
On the Tools menu, point to Macro, and then click Stop Recording.
Switch to Sheet2 in the workbook (click the Sheet2 tab at the bottom of the workbook window).
On the Tools menu, point to Macro, and then click Macros.
In the Macro name list, click Macro1, and then click Run.
Note the run-time error message.
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.
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 Microsoft Advisory Services. For more information, visit these Microsoft Web sites: