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

Article translations Article translations
Article ID: 277577 - View products that this article applies to.
This article was previously published under Q277577
Expand all | Collapse all

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 Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS 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.

Properties

Article ID: 277577 - Last Review: January 29, 2007 - Revision: 2.7
APPLIES TO
  • Microsoft Excel 2002 Standard Edition
Keywords: 
kbbug kberrmsg kbpending KB277577

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com