PRJ4: Error Running Macro to Paste Date Field to Number Field
  
PSS ID Number: Q137021
Article last modified on 01-30-1996
 
4.00
 
WINDOWS
 

--------------------------------------------------------------------
The information in this article applies to:
 
 - Microsoft Project for Windows, version 4.0
--------------------------------------------------------------------
 
SYMPTOMS
========
 
In Microsoft Project, when you run a macro that pastes a date field value
to a number field in your project, you may receive the following error
message:
 
   The entry you typed in the Number field is not valid. You can only
   enter numbers in the Number field
 
CAUSE
=====
 
This behavior occurs if a macro copies a value in a date field to a cell in
a number field. For example, if you turn on the macro recorder, and you
copy a value in the Finish field, and paste the value to a cell in the
Number1 field, the Paste Special dialog box appears. If you paste the value
as Text Data format, the value is pasted to the Number column as a serial
number. However, when you run the macro, you receive the error message
described above.
 
This behavior occurs because when you use the Paste Special dialog box,
Microsoft Project uses the text format to correctly paste a date value into
a column formatted for a number value. However, when you use the
EditPasteSpecial method in a macro (recorded when you display the Paste
Special dialog box), Microsoft Project uses the BIFF (Binary File Format)
instead of the text format.
 
WORKAROUND
==========
 
To work around this problem, you can use any of the following methods:
 
Method 1: Use the SendKeys statement in your macro as in the following
          example:
 
             Sub Macro1()
 
                ' Select and copy values in Finish column
                SelectTaskColumn Column:="Finish"
                EditCopy
                ' Select destination column, Number1
                SelectTaskColumn Column:="Number1"
                ' Send keystrokes for Paste Special dialog box
                SendKeys "t{enter}"
                EditPasteSpecial
 
             End Sub
 
Method 2: Display the Paste Special dialog box so that the user can click
          the desired options, as in the following example:
 
             Sub Macro1()
 
                ' Select and copy values in Finish column
                SelectTaskColumn Column:="Finish"
                EditCopy
                ' Select destination column, Number1
                SelectTaskColumn Column:="Number1"
                ' Display Paste Special dialog box for user to
                ' select desired options
             EditPasteSpecial
 
             End Sub
 
Microsoft provides examples of Visual Basic 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. This Visual Basic procedure is provided 'as is' and
Microsoft does not guarantee that it can be used in all situations.
Microsoft does not support modifications of this procedure to suit customer
requirements for a particular purpose.
 
REFERENCES
==========
 
For more information about copying columns in Microsoft Project, click the
Index tab in Microsoft Project Help, type the following text
 
   copying columns
 
and then double-click the selected text to go to the "Copying And Moving
Fields, Rows, And Columns" topic.
 
KBCategory: kbprg kbcode
KBSubcategory: projwin
 
Additional reference words: 4.00 Paste Special
=============================================================================
Copyright Microsoft Corporation 1996.
