Import a time from Excel

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Ghost24de
Newbie
Posts: 13
Joined: Thu Aug 15, 2013 11:24 am

Import a time from Excel

Post by Ghost24de » Tue Oct 29, 2013 9:40 pm

Hi,

i will import a time from a Excel Cell.

First problem is:

like this
XLGetCell>xlBook,InputVar,1,9,InputTime

The value of this cell ist 22:00:00 (h:m:s european time)

But, after the import .... Macroshedu.. lose the format and so i recive the value inside the variable 0.916666666666667.

How can i do, that i have not 0.916666666666667?
I need this format h:m:s



Second one is,
if i close with
XLQuit>xlBook

but the Excel (process) is open and will not be close!
I only can close the process with the killproce... command... but i think thats not the fine and right way


great thanks for your help

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Oct 30, 2013 8:10 pm

Hi Ghost24de,

Here is some early feedback on what "may be" happening there and an idea on how you could convert 0.916666666666667 back to 22:00:00

I notice that...
22/24 = 0.91666666666666666666666666666667

So...
1/24 = 1 hour = 0.041666666666666666666666666666667

- in a loop, count how many times you can subtract 0.0416 from total, that is hours value

(1/60)/24 = 1 min = 0.00069444444444444444444444444444444

- in a loop, count how many times you can subtract 0.000694 from remainder above, that is min value

((1/60)/60)/24 = 1 sec = 0.000011574074074074074074074074074074

- in a loop, count how many times you can subtract 0.0000115740 from remainder above, that is sec value

- now that you have hr, min and sec values, build a string using those values separated by colons :

And now someone will post an easier way... take it away...
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Ghost24de
Newbie
Posts: 13
Joined: Thu Aug 15, 2013 11:24 am

....

Post by Ghost24de » Thu Oct 31, 2013 6:50 pm

mhhh
is ther noone ... with a idea from a easier way?

mhh i think .. i will splitt the excel cell into 3 single cells.. so one for the hour, one for the min and one for the sec... so i must import 3 values, but i think it is easier to go this way to write a loop and counter inside the makro. 8)

And for the second answer... with the close porblem from excel?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Nov 01, 2013 9:44 am

When you use XLGetCell it always will return the VALUE. The formatting is handled by Excel. You are seeing the raw data.

What you can do is use VBScript's FormatDateTime function to format the time the way you want it:

VBEval>FormatDateTime(0.916666666666667,3),formattedTime
MessageModal>formattedTime

So you could use this with XLGetCell:

XLGetCell>xlBook,InputVar,1,9,InputTime
VBEval>FormatDateTime(%InputTime%,3),formattedTime
MessageModal>formattedTime
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Post by hagchr » Fri Nov 01, 2013 10:19 am

Hi,

I get an error code if excel is formatted with one of the excel date formats. Unformatted it works well, so format seems to impact (I am using excel 2010)

Microsoft VBScript Compilation error :1006.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Nov 01, 2013 10:26 am

This works for me:

XLOpen>%USERDOCUMENTS_DIR%\book1time.xlsx,1,xlH
XLGetCell>xlH,Sheet1,1,1,theTime
VBEval>FormatDateTime(%theTime%,3),result

I tried it with cell A1 formatted to Time, of Type: hh:mm:ss like so:

Image

If it isn't working for you can you share what format you are using.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Post by hagchr » Fri Nov 01, 2013 10:42 am

I was first playing with pulling also the date information and still had the date format left on (mm/dd/yy). (Admit maybe inconsistent with looking for the time but I did not think the format would affect it)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts