Re: Find Text between Markers - III

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: Additional TreeView Property?
    ... information including what you are currently putting in the tag and use the ... Dim iFile As Integer ... Dim FileName As String ...
    (microsoft.public.vb.general.discussion)
  • Re: VBA: Selectively Deleting Notes in a PowerPoint PPT
    ... tag that with a PPT tag. ... Dim oSl As Slide ... Dim oSh as Shape ... For Each oSl In ActivePresentation.Slides ...
    (microsoft.public.powerpoint)
  • Re: Word 2007 Combining Bibliography from Multiple Documents
    ... Open document 1, copy the citations from the current list to the master source list. ... It might be a bit of a hassle as during the copying of the elements of the second current list to the master list, you will have to press yes to overwrite the common sources from the first current list as they will share the same tag. ... Dim doc1 As Document ' Version by person 1 ...
    (microsoft.public.word.docmanagement)
  • Re: The third user could merge them through Manage Sources.
    ... If another user created additional citations in a different section on the ... Dim doc1 As Document ' Version by person 1 ... Dim tag As String ... Set src = doc1.Bibliography.Sources ...
    (microsoft.public.word.docmanagement)
  • Re: shorts and longs
    ... aren't all TIFF IFD entries and tag values stored as unsigned values? ... so, when i Dim m_Compression as Integer and the return value is 32773, i get ... > as a long which is what you store in your application. ... > Dim TempWord As Integer ...
    (microsoft.public.vb.general.discussion)