.AddDays( ) function

Add-in Express™ Support Service
That's what is more important than anything else

.AddDays( ) function
get error when trying to use 
Neenarg


Guest


Using ADX2008, VS2005

I must be missing something obvious but I am trying to to get a date from a cell in excel and place a date based on that date (plus 5 days for example).

I have tried innumerable variations of the following but I always seem to get an error and can not work out how the code should be..

The error I get from the following is "Conversion from type 'Range' to type 'Date' is not valid."

wksheet is my worksheet, c is a row reference in a for x = 1 to y loop. dateposted is based on a string which is a UK format date.

Dim dateposted as Date

dateposted = CDate(wksheet.Cells(c, 6)).AddDays(5)
wksheet.Cells(c, 13).value = dateposted.ToShortDateString


Is it a problem with the original date cell ? Any suggestions?
Posted 18 Mar, 2008 19:11:06 Top
Neenarg


Guest


I just read something about the date format in COM objects not being compatible with .NET

Something to do with converting them to a double, and using .ToOADate - anybody know how to do this in ADX? (add n days to a UK format date string)

Thanks,
Trevor
Posted 19 Mar, 2008 07:59:05 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Trevor.

private void adxCommandBarButton1_Click(object sender)
{
Excel.Worksheet sheet =
ExcelApp.ActiveSheet as Excel.Worksheet;

object date = (sheet.Cells[1, 1] as Excel.Range).Value2;
if (date is double)
{
DateTime dateValue = DateTime.FromOADate((double)date);
dateValue = dateValue.AddDays(5);
}
}
Posted 19 Mar, 2008 09:12:31 Top
Neenarg


Guest


Thats perfect! Thanks Sergey!
Posted 19 Mar, 2008 11:37:40 Top