XL97: Problems with Arguments of PasteSpecial Method

Last reviewed: March 13, 1998
Article ID: Q171281
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SYMPTOMS

In Microsoft Excel 97, if you write a Visual Basic for Applications macro that uses the PasteSpecial method, the macro may not work correctly if it attempts to perform either of the following actions:

  • Use Paste Special to paste validation
  • Use Paste Special to paste all information except borders

For example, when the macro attempts to paste information except borders, nothing is pasted.

Note that the same macro works correctly in earlier versions of Microsoft Excel.

CAUSE

This problem occurs because the Paste argument used by the PasteSpecial method uses the wrong value; it uses the value 6 instead of the value 7. Because the value 6 is used, the xlPasteAllExceptBorders constant incorrectly causes validation formatting to be pasted.

To paste information except borders, the xlPasteAllExceptBorders constant should use a value of 7. When the value is 6, the xlPasteAllExceptBorders constant causes the PasteSpecial method to paste validation formatting when you run the macro.

There is no constant that causes all information except borders to be pasted.

NOTE: There is no xlPasteValidation constant, either in Visual Basic or mentioned in the Help topic for the PasteSpecial method.

WORKAROUNDS

Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

To work around this problem, use the Paste argument and set it to the correct value. To do this, modify the macro so that it resembles one of the following examples.

Paste Validation Only

To paste only validation formatting, change the value of the Paste argument to 6, as in the following example:

   Selection.PasteSpecial Paste:=6, Operation:=xlNone

To avoid confusion, Microsoft recommends that you use this method instead of using the xlPasteAllExceptBorders constant because it does not perform the correct operation.

To Paste All Information Except Borders

If you want to paste all copied information except borders, change the value of the Paste argument to 7, as in the following example:

   Selection.PasteSpecial Paste:=7, Operation:=xlNone

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

If you click Paste Special on the Edit menu while recording a Visual Basic macro in Microsoft Excel 97, the Paste argument recorded in the code may be incorrect. For example, the action you record and the constant that is recorded are listed in the following table.

   Paste Special action   Recorded constant
   ----------------------------------------------

   Validation             xlPasteAllExceptBorders

   All Except Borders     7

Note that if you run the recorded code, it works correctly even though it does not appear to be correct.

If you write a macro or if you edit a recorded macro, the PasteSpecial method may not work correctly if you use the constant noted in Help.


Additional query words: XL97
Keywords : kbcode kbprg kbdocerr
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbprb
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.