Re: Find Text between Markers - III
- From: "Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 26 Oct 2007 15:07:17 -0400
Steve,
Yes. i and y are numerical values. You are basically finding the first
tag. Collasping the range to the end of the found range. Finding the
second tag. Settting a duplicate range. Setting the start of the duplicate
range to the position in the document represented by i + 1, then backing up
the duplicate range by the length of the second tag. That leaves a range
the bounds the text between the tags.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
sjwopg wrote:
Thanks. It works great. I won't have to look for the same markers,
but may have to look for a bunch of different markers and do the same
thing. My thought is to set a couple of variables for the beginning
and ending markers, along with a bookmark variable. Then I'll keep
looping through the code changing the variables. I use this concept
all the time with Access.
I stepped through the code and noticed that the i and y variables were
numbers. Are those the actual position of those characters in the
document?
Thanks again. I'm sure I'll have a few more questions. I'm also going
to run through the Learn VBA in 15 minutes tutorial on the MVPS site.
Steve
"Greg Maxey" wrote:
Something like this:
Sub ScratchMacro()
Dim oRng As Range
Dim myRange As Range
Dim i As Long
Dim y As Long
Set oRng = ActiveDocument.Range
ActiveDocument.Range(0, 0).Select
With oRng.Find
.Text = "[FMR Data]"
.Wrap = wdFindStop
If .Execute Then
i = oRng.End
oRng.Collapse direction:=wdCollapseEnd
.Text = "[FMR Data1]"
y = Len(.Text)
If .Execute Then
oRng.Select
Set myRange = oRng.Duplicate
myRange.Start = i + 1
myRange.End = oRng.End - y
End If
End If
End With
ActiveDocument.Bookmarks("Test").Range.InsertAfter myRange.Text
End Sub
If there are multiple instances of text to be found you would need
change the If .Execute statement to a While .Execute and then sort
out where you want each instance put.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
"sjwopg" <sjwopg@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AB939923-B3AC-4652-BE1E-62D7B3B7A439@xxxxxxxxxxxxxxxx
I found some discussion about this topic, but I'm not getting it.
Here is my
specific issue:
[FMR Data]
12/01/07 $1,500,000 $12,500
12/01/08 $1,200,000 $10,000
12/01/09 $1,680,000 $14,000
[FMR Data1]
I need to take the text between [FMR Data] and [FMR Data1] and copy
it to a
different section of the document.
The spaces in the text represent tab stops. The selection would be
the beginning of the line with 12/01/07 through the end of the line
with 12/01/09, including tab stops.
I've got the copying and pasting down, but selecting the text is
problematic.
I am quite proficient using VBA in Access and Excel, and I realize
that the
solution has to be quite simple. I must be having a senior moment.
Your help
is really appreciated.
Thanks,
Steve
.
- Follow-Ups:
- Re: Find Text between Markers - III
- From: sjwopg
- Re: Find Text between Markers - III
- References:
- Re: Find Text between Markers - III
- From: Greg Maxey
- Re: Find Text between Markers - III
- From: sjwopg
- Re: Find Text between Markers - III
- Prev by Date: Word 2007 GetAddress Problem
- Next by Date: Re: Selection/Table & Text
- Previous by thread: Re: Find Text between Markers - III
- Next by thread: Re: Find Text between Markers - III
- Index(es):
Relevant Pages
|