Working with formulas in Word tables - calculating time on scene.

H

HCFRAdmin

I am creating forms to be filled out on the computer and then emailed to me.
I am trying to create a formula in a table that can tell us how many minutes
(hours and minutes) that our personnel spent on a scene. For example: I
have a box that they can enter their "Response Time" in and then I have
another box where they can enter "Time Clear of Scene". I want a formula in
the following cell to total the amount of hours and minutes they spent at
this certain call. How do I do this? Help? Please??? Thanks in advance!

Christy
 
D

Doug Robbins - Word MVP

' Macro to calculate the elapsed time for formfields with Date format of
HH:mm

' Macro created 16 May 1999 by Doug Robbins - Word MVP

'

Start = ActiveDocument.FormFields("StartTime").Result

StartHour = Val(Left(Start, 2))

StartMinutes = Val(Right(Start, 2))

StartTimeMinutes = StartHour * 60 + StartMinutes

Finish = ActiveDocument.FormFields("FinishTime").Result

FinishHour = Val(Left(Finish, 2))

FinishMinutes = Val(Right(Finish, 2))

FinishTimeMinutes = FinishHour * 60 + FinishMinutes

ElapsedMinutes = FinishTimeMinutes - StartTimeMinutes

ElapsedHours = Int(ElapsedMinutes / 60)

ElapsedMinutes = ElapsedMinutes - ElapsedHours * 60

ActiveDocument.FormFields("Duration").Result = Str(ElapsedHours) & ":" &
Format(ElapsedMinutes, "00")


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
T

Tony Jollans

If you're not going to bother with any validation then this would be a
little simpler ..

With ActiveDocument
.FormFields("Duration").Result _
= Format(CDate(.FormFields("FinishTime").Result) _
- CDate(.FormFields("StartTime").Result), "h:mm")
End With
 
H

HCFRAdmin

Tony,
That would be great, if only I knew how to create Macros. I thought there
would be a formula that I could use without getting too technical. Macros
are probably your second language, however, I don't know how to create or use
them. I'm sorry. Perhaps I should start there, huh?

Christy
 
T

Tony Jollans

Sorry Christie,

As you say, macros are a sort of second language to me and I forget that
they are completely alien to others :)

Suzanne has pointed you to instructions for installing them - I hope it goes
well.

It would be possible to concoct a formula but it would be longer than the
code and you really wouldn't like it. If that is what you would like, please
come back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top