use range object

F

FotoArt

hello everyone

i have here a piece of code provided by doug.
i need to do the search after putting the whole content of my page into a
range object.
i hope by doing that i will be able to leave the selecion intact.
any help is appreciated.


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


thanx
ahmed
 
H

Helmut Weber

Hi Ahmed,

you need to put the content of a page
or of the whole doc into a range?

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
F

FotoArt

hello weber

i have converted the code (as provided below) so the search passes the value
to a variable.
my problem is my selection point moves after the search is conduced. it goes
to the top ofthe document.
by putting the whole doc in to a range object and do the searching i am
hoping my selection point will remain where it is.
hope theres a better way.

btw the code runs everytime a document is saved.
any help is appreciated.
hweres he modified code

Private Function mySoundBytes()
Dim Seconds As Long


Seconds = 0
Selection.HomeKey wdStory
Selection.Find.ClearFormatting

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

Selection.Collapse wdCollapseEnd
Loop
End With

mySoundBytes = Seconds

End Function

thanx
ahmed
 
H

Helmut Weber

Hi Ahmed,

something along these lines, untested:

Private Function mySoundBytes()
Dim Seconds As Long
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
Seconds = 0
With rDcm.Find
.Text = "[0-9]{1}:[0-9]{2}:[0-9]{2}"
.Wrap = wdFindStop
.MatchWildcards = True
While .Execute
Seconds = Seconds + Val(Left(selection, 1)) * 3600 + _
Val(Mid(selection, 4, 2)) * 60 + _
Val(Right(selection, 2))
rDcm.Collapse wdCollapseEnd
Wend
End With
mySoundBytes = Seconds
End Function

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
F

FotoArt

hello weber

your code is working fine but it is not what I expected.
By Looking at the code can u recommend a way how I could use the function
but keep my insertion or selection point remain where it was before the
function began processing the document.

thanx
ahmed
 
H

Helmut Weber

Hi Ahmed,
your code is working fine but it is not what I expected.
By Looking at the code can u recommend a way how I could use the function
but keep my insertion or selection point remain where it was before the
function began processing the document.

I'm sorry,
I can't see anything in my code,
that would move the selection.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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