retrieve data from a word dco

C

clara

Hi all,

I have some data scattered in a word doc, but fortunately the data is
formated like R12345 and embraced inside [ ] like [R12345], in order to
retrieve value R12345 ,
what am I going to do.


thank you so much for your help

Clara
 
G

Graham Mayor

What do you want to do with the data having found it? The following macro
will locate the data in square brackets that matches your layout and assigns
it in turn to a range variable oRng. You can do what you want with that
range eg display it in a message box as in the example

Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "\[[0-9A-Z]{1,}\]"
Do While .Execute(Forward:=True, _
MatchWildcards:=True) = True
oRng.Start = oRng.Start + 1
oRng.End = oRng.End - 1
'orng is the text in the brackets e.g.
MsgBox oRng
oRng.Collapse wdCollapseEnd
Loop
End With


If you want it to find *anything* between square brackets change the line
.Text = "\[[0-9A-Z]{1,}\]"
to
.Text = "\[*\]"

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

clara

Hi Jay,

thank you very much

Clara


Jay Freedman said:
See http://www.gmayor.com/replace_using_wildcards.htm. For the particular
data you described, the search term to use is

\[R[0-9]@\]

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Hi all,

I have some data scattered in a word doc, but fortunately the data is
formated like R12345 and embraced inside [ ] like [R12345], in
order to retrieve value R12345 ,
what am I going to do.


thank you so much for your help

Clara


.
 
C

clara

Hi Graham,

Thank you very much, I'll try your code

Clara



Graham Mayor said:
What do you want to do with the data having found it? The following macro
will locate the data in square brackets that matches your layout and assigns
it in turn to a range variable oRng. You can do what you want with that
range eg display it in a message box as in the example

Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "\[[0-9A-Z]{1,}\]"
Do While .Execute(Forward:=True, _
MatchWildcards:=True) = True
oRng.Start = oRng.Start + 1
oRng.End = oRng.End - 1
'orng is the text in the brackets e.g.
MsgBox oRng
oRng.Collapse wdCollapseEnd
Loop
End With


If you want it to find *anything* between square brackets change the line
.Text = "\[[0-9A-Z]{1,}\]"
to
.Text = "\[*\]"

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



clara said:
Hi all,

I have some data scattered in a word doc, but fortunately the data is
formated like R12345 and embraced inside [ ] like [R12345], in order to
retrieve value R12345 ,
what am I going to do.


thank you so much for your help

Clara


.
 
C

clara

HI Graham,

I've copied your code into my module created VB 2005, on this line

oRng.Collapse wdCollapseEnd

the "wdCollapseEnd" was underlined as not declared, maybe there is a
mismatch between VBA and .NET

Thank you

Clara

--
thank you so much for your help


Graham Mayor said:
What do you want to do with the data having found it? The following macro
will locate the data in square brackets that matches your layout and assigns
it in turn to a range variable oRng. You can do what you want with that
range eg display it in a message box as in the example

Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "\[[0-9A-Z]{1,}\]"
Do While .Execute(Forward:=True, _
MatchWildcards:=True) = True
oRng.Start = oRng.Start + 1
oRng.End = oRng.End - 1
'orng is the text in the brackets e.g.
MsgBox oRng
oRng.Collapse wdCollapseEnd
Loop
End With


If you want it to find *anything* between square brackets change the line
.Text = "\[[0-9A-Z]{1,}\]"
to
.Text = "\[*\]"

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



clara said:
Hi all,

I have some data scattered in a word doc, but fortunately the data is
formated like R12345 and embraced inside [ ] like [R12345], in order to
retrieve value R12345 ,
what am I going to do.


thank you so much for your help

Clara


.
 
C

clara

Hi Graham,

I got it. In .NET it should be translated into:

Collapse(Word.WdCollapseDirection.wdCollapseEnd)

but what does this enum wdCollapseEnd mean?

Clara

Thank you


Graham Mayor said:
What do you want to do with the data having found it? The following macro
will locate the data in square brackets that matches your layout and assigns
it in turn to a range variable oRng. You can do what you want with that
range eg display it in a message box as in the example

Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "\[[0-9A-Z]{1,}\]"
Do While .Execute(Forward:=True, _
MatchWildcards:=True) = True
oRng.Start = oRng.Start + 1
oRng.End = oRng.End - 1
'orng is the text in the brackets e.g.
MsgBox oRng
oRng.Collapse wdCollapseEnd
Loop
End With


If you want it to find *anything* between square brackets change the line
.Text = "\[[0-9A-Z]{1,}\]"
to
.Text = "\[*\]"

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



clara said:
Hi all,

I have some data scattered in a word doc, but fortunately the data is
formated like R12345 and embraced inside [ ] like [R12345], in order to
retrieve value R12345 ,
what am I going to do.


thank you so much for your help

Clara


.
 
D

Doug Robbins - Word MVP

It collapses the range to its end (so that in effect, it does not contain
anything); handy though if you want to get hold of something after the end
of the range, or prevent do code from going into an endless loop because it
continues to act upon the initial range.

--
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, originally posted via msnews.microsoft.com

clara said:
Hi Graham,

I got it. In .NET it should be translated into:

Collapse(Word.WdCollapseDirection.wdCollapseEnd)

but what does this enum wdCollapseEnd mean?

Clara

Thank you


Graham Mayor said:
What do you want to do with the data having found it? The following macro
will locate the data in square brackets that matches your layout and
assigns
it in turn to a range variable oRng. You can do what you want with that
range eg display it in a message box as in the example

Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "\[[0-9A-Z]{1,}\]"
Do While .Execute(Forward:=True, _
MatchWildcards:=True) = True
oRng.Start = oRng.Start + 1
oRng.End = oRng.End - 1
'orng is the text in the brackets e.g.
MsgBox oRng
oRng.Collapse wdCollapseEnd
Loop
End With


If you want it to find *anything* between square brackets change the line
.Text = "\[[0-9A-Z]{1,}\]"
to
.Text = "\[*\]"

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



clara said:
Hi all,

I have some data scattered in a word doc, but fortunately the data is
formated like R12345 and embraced inside [ ] like [R12345], in order
to
retrieve value R12345 ,
what am I going to do.


thank you so much for your help

Clara


.
 
C

clara

Hi Doug,

it is a real handy feature, thank you

Clara

have a nice weekend


Doug Robbins - Word MVP said:
It collapses the range to its end (so that in effect, it does not contain
anything); handy though if you want to get hold of something after the end
of the range, or prevent do code from going into an endless loop because it
continues to act upon the initial range.

--
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, originally posted via msnews.microsoft.com

clara said:
Hi Graham,

I got it. In .NET it should be translated into:

Collapse(Word.WdCollapseDirection.wdCollapseEnd)

but what does this enum wdCollapseEnd mean?

Clara

Thank you


Graham Mayor said:
What do you want to do with the data having found it? The following macro
will locate the data in square brackets that matches your layout and
assigns
it in turn to a range variable oRng. You can do what you want with that
range eg display it in a message box as in the example

Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "\[[0-9A-Z]{1,}\]"
Do While .Execute(Forward:=True, _
MatchWildcards:=True) = True
oRng.Start = oRng.Start + 1
oRng.End = oRng.End - 1
'orng is the text in the brackets e.g.
MsgBox oRng
oRng.Collapse wdCollapseEnd
Loop
End With


If you want it to find *anything* between square brackets change the line
.Text = "\[[0-9A-Z]{1,}\]"
to
.Text = "\[*\]"

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



Hi all,

I have some data scattered in a word doc, but fortunately the data is
formated like R12345 and embraced inside [ ] like [R12345], in order
to
retrieve value R12345 ,
what am I going to do.


thank you so much for your help

Clara


.
 

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