How to extract all entries some text into new document?

A

avkokin

Hello.
There is a document which has some text (copy from forums) and some
areas as like: "send 18:05 23.08.08". I need to extract all such areas
to new document without of text "send".
I tried use next code (below), but it cycled.
My code:
Sub extractDateTime()
Dim dt As String
Dim oRange As Range
Dim newDoc As Document
Dim actDoc As Document

Set actDoc = ActiveDocument
Set oRange = actDoc.Range
Set newDoc = Documents.Add

actDoc.Activate
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.Text = "send ([0-9]{1;}:[0-9]{1;} [0-9]{1;}.[0-9]{1;}.[0-9]{1;})"
.Execute
While .Found
dt = Selection.Text
newDoc.Activate
InsertAfter dt & vbCr
Wend
End With
End Sub

I know that I have the bad logic. But I want to ask for you: where is
my error?
Thank you very much.
 
G

Graham Mayor

Nearly :)

Dim dt As String
Dim at As Variant
Dim oRange As Range
Dim newDoc As Document
Dim actDoc As Document

Set actDoc = ActiveDocument
Set oRange = actDoc.Range
Set newDoc = Documents.Add

actDoc.Activate
Selection.HomeKey wdStory
With Selection.Find
.Replacement.ClearFormatting
.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.Text = "send ([0-9]{1;}:[0-9]{1;} [0-9]{1;}.[0-9]{1;}.[0-9]{1;})"
.Replacement.Text = ""
.MatchWildcards = True
While .Execute
dt = Selection.Text
at = Split(dt, " "; 2)
dt = at(1)
newDoc.Activate
Selection.InsertAfter dt & vbCr
actDoc.Activate
Wend
newDoc.Activate
End With

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