how to do calculations on a word page

F

FotoArt

hello everyone

my work involves writing news scripts. And I need to put the length of
soundbites on the page like so
sound bite: 00:02:30

Each newsscript is a section.
there may be two to three sound bites on every page.
How do I add these (hh:mm:ss) figures and give the total in the header or
footer.

SHould they be bookmarks along with a field.
any help will be appreciated.

thanx
ahmed
 
D

Doug Robbins - Word MVP

Is the document, just one page in length? When you say each news script is
a section, do you me Section as it is used in Word, i.e. is each news script
separated from the next by a Section Break?

In the absence of precise information, the following may do what you want,
but may require modification depending upon the additional information
requested:

Dim Seconds As Long
Seconds = 0
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="[0-9]{2}:[0-9]{2}:[0-9]{2}", Forward:=True,
_
MatchWildcards:=True, Wrap:=wdFindStop, MatchCase:=True) = True
Seconds = Seconds + Val(Left(Selection, 2)) * 3600 +
Val(Mid(Selection, 4, 2)) * 60 + Val(Right(Selection, 2))
Selection.Collapse wdCollapseEnd
Loop
End With
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
.Text = "Total Time = " & Format(Int(Seconds / 3600), "00") & ":" &
Format(Int((Seconds Mod 3600) / 60), "00") & ":" & Format((Seconds Mod 60),
"00")
.ParagraphFormat.Alignment = wdAlignParagraphRight
End With



--
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
 
F

Fotoart

thanks i have make it work.

Doug Robbins - Word MVP said:
Is the document, just one page in length? When you say each news script
is a section, do you me Section as it is used in Word, i.e. is each news
script separated from the next by a Section Break?

In the absence of precise information, the following may do what you want,
but may require modification depending upon the additional information
requested:

Dim Seconds As Long
Seconds = 0
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:="[0-9]{2}:[0-9]{2}:[0-9]{2}",
Forward:=True, _
MatchWildcards:=True, Wrap:=wdFindStop, MatchCase:=True) = True
Seconds = Seconds + Val(Left(Selection, 2)) * 3600 +
Val(Mid(Selection, 4, 2)) * 60 + Val(Right(Selection, 2))
Selection.Collapse wdCollapseEnd
Loop
End With
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
.Text = "Total Time = " & Format(Int(Seconds / 3600), "00") & ":" &
Format(Int((Seconds Mod 3600) / 60), "00") & ":" & Format((Seconds Mod
60), "00")
.ParagraphFormat.Alignment = wdAlignParagraphRight
End With



--
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

FotoArt said:
hello everyone

my work involves writing news scripts. And I need to put the length of
soundbites on the page like so
sound bite: 00:02:30

Each newsscript is a section.
there may be two to three sound bites on every page.
How do I add these (hh:mm:ss) figures and give the total in the header or
footer.

SHould they be bookmarks along with a field.
any help will be appreciated.

thanx
ahmed
 
F

FotoArt

Hello Doug
How can I put the content of the document to a range object and do the search.
I want to leave the real document alone and do the search separately.
Because if i do the search on the document my insertion point goes to the top
of the document.

heres how i have tried to modify the code.

Private Function mmySoundBytes()
Dim Seconds As Long
Dim rngDoc As Range

Set rngDoc = ActiveDocument.Content
Seconds = 0

rngDoc.Collapse wdCollapseStart
rngDoc.SetRange Start:=rngDoc.Start, End:=rngDoc.End
rngDoc.Find.ClearFormatting

With rngDoc.Find
Do While .Execute(Findtext:="[0-9]{1}:[0-9]{2}:[0-9]{2}", _
Forward:=True, _
MatchWildcards:=True, _
Wrap:=wdFindStop, _
MatchCase:=True) = True
MsgBox Selection
Seconds = Seconds + Val(Left(Selection, 1)) * 3600 + _
Val(Mid(Selection, 4, 2)) * 60 + _
Val(Right(Selection, 2))

rngDoc.Collapse wdCollapseEnd
Loop
End With
mmySoundBytes = Seconds

End Function


any help will be appreciated
thanx
ahmed
 
D

Doug Robbins - Word MVP

See response to your later post.

--
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
 

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