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:
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:
- 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.
RESOLUTIONMicrosoft 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:
- On the Tools menu, point to Macro, and then click Macros.
- In the Macro name list, click Macro1, and then click Edit.
- Delete the following code near the bottom of the module sheet:
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbbug kberrmsg kbpending KB277577 |
---|
|