Re: Need help with a date/excel applescript please.
Re: Need help with a date/excel applescript please.
- Subject: Re: Need help with a date/excel applescript please.
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 02 Feb 2003 10:44:57 -0800
On 2/2/03 10:11 AM, "montana" <email@hidden> wrote:
>
I'm trying to create an excel template that I can add two different dates and
>
time into two cells formatted like such:
>
>
1/17/03 12:00
If they're formatted like that, aligned to the right edge of the cell, they
are already date data type, not text. You can tell for sure by
double-clicking the cell - it should now appear as
1/17/2003 12:00:00 PM
And Excel's AppleScript honors the date data type if you get Value of Cell.
You do not need "as date". (And if you did, i.e. if you used a different
format that Excel did not recognize as a date but as text, you still
couldn't coerce it 'as date': you'd have to do
tell me set theDate to date "Saturday, January 17, 2003"
).
>
>
The applescript should take these two values, convert them to date objects,
They're already date objects.
>
do
>
some calculations and return a date oblect that is the difference of the first
>
two date objects as text in a new cell on the spreadsheet.
The main thing is you have to use Value of Cell, not just Cell:
tell application "Microsoft Excel"
Activate
set sdate to Value of Cell "B1"
set edate to Value of Cell "B2"
set diff to edate - sdate
set hoursdiff to diff div hours
set secsLO to diff mod hours
set minsdiff to secsLO div minutes
set answ to (hoursdiff & " hours;" & minsdiff & " minutes.") as string
set Value of Cell "B3" to answ
display dialog (sdate & " - " & edate & ": " & answ) as string
end tell
>
>
This is what I have so far with the last line being a test:
>
tell application "Microsoft Excel"
>
Activate
>
set sdate to Cell "B1" as date
>
set edate to Cell "B2" as date
>
set diff to edate - sdate
>
set hoursdiff to diff div hours
>
set secsLO to diff mod hours
>
set minsdiff to secsLO div minutes
>
set answ to hoursdiff & " hours;" & minsdiff & " minutes." as text
>
--set Cell "B3" to answ
>
display dialog (sdate & edate & answ) as text
>
end tell
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.