Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

↑ Back to the top


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.

↑ Back to the top


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
    					

↑ Back to the top


Status

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

↑ Back to the top


Keywords: KB277577, kbpending, kberrmsg, kbbug

↑ Back to the top

Article Info
Article ID : 277577
Revision : 9
Created on : 1/29/2007
Published on : 1/29/2007
Exists online : False
Views : 336