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.

XL2000: "PasteSpecial method of Range class failed" Error When Running a Macro


View products that this article applies to.

Symptoms

When you run a macro that contains the xlColumnWidths member, you receive the following error message:
Run-time error '1004':
PasteSpecial method of Range class failed"

↑ Back to the top


Cause

This error message occurs when the following conditions are true:
  • You have a line of code in your macro similar to the following:
    Selection.PasteSpecial Paste:=xlColumnWidths
    						
    -or-

  • You record a macro and paste the column widths using the Paste Special dialog box (on the Edit menu, click Paste Special).

↑ Back to the top


Workaround

To work around this problem use the number 8 in place of the xlColumnWidths value. The number 8 represents the Column Widths paste constant which is part of Microsoft Excel. The following example illustrates this:

Change this code
Selection.PasteSpecial Paste:=xlColumnWidths
				
to this:
Selection.PasteSpecial Paste:=8
				

↑ Back to the top


More information

Although Microsoft Excel displays the xlColumnWidths member when you use the Macro Recorder to record a macro, it is not defined in the object model of Excel. Because it is not defined in the object model, it does not appear in the Object Browser in the Visual Basic Editor (on the View menu, click Object Browser).

If your code contains multiple instances of the xlColumnWidths member, make the following declaration at the beginning of the macro, which will prevent you from having to change every occurrence of xlColumnWidths:
Const xlColumnWidths = 8
				

↑ Back to the top


Keywords: KB231090, kbpending, kberrmsg, kbdtacode, kbbug

↑ Back to the top

Article Info
Article ID : 231090
Revision : 5
Created on : 6/22/2014
Published on : 6/22/2014
Exists online : False
Views : 220