How to: Store and Retrieve Date Values in Excel Ranges
Note |
|---|
|
Some code examples in this topic use the this or Me keyword or the |
If you store a date value that falls on or after 1/1/1900 in a Microsoft Office Excel 2003 range using Microsoft Visual Studio 2005 Tools for the Microsoft Office System, it is stored in OLE Automation (OA) format. You must use the FromOADate method to retrieve the value of OLE Automation (OA) dates, If the date is earlier than 1/1/1900, it is stored as a string.
Note |
|---|
|
Excel dates differ from OLE Automation dates for the first two months of 1900. There are also differences if the 1904 date system option is checked. The code examples below do not address these differences. |
To store a date value in a named range
-
Create a NamedRange control on cell A1.
-
Set today's date as the value for
NamedRange1.
To retrieve a date value from a named range
-
Retrieve the date value from
NamedRange1.
Compiling the Code
-
This code must be placed in a sheet class, not in the
ThisWorkbookclass.
See Also
Tasks
How to: Send Values to Worksheet CellsHow to: Refer to Worksheet Ranges in Code
How to: Add NamedRange Controls to Worksheets
Concepts
Excel TasksExcel Object Model Overview
NamedRange Control
Understanding Optional Parameters in COM Interop
Note