Hi,

I would like to mark up a text and have a macro select the pieces of text
from one mark to another (eg all text between * to %), copy it and then
paste it into a new file.

Any suggestions on how this can be done neatly?
(I can do the copy/paste part of it. But I don't know how to instruct
selection between the marks. I would suppose one could use find. But know how
to select when finding.)

--
eugene

Re: macro to select text from one point to another by Greg

Greg
Tue Feb 13 11:12:23 CST 2007

On Feb 13, 11:39 am, eugene <eug...@discussions.microsoft.com> wrote:
> Hi,
>
> I would like to mark up a text and have a macro select the pieces of text
> from one mark to another (eg all text between * to %), copy it and then
> paste it into a new file.
>
> Any suggestions on how this can be done neatly?
> (I can do the copy/paste part of it. But I don't know how to instruct
> selection between the marks. I would suppose one could use find. But know how
> to select when finding.)
>
> --
> eugene

Maybe something like this:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "[\*]*%"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
While .Execute
'Clip special characters from found text
oRng.Start = oRng.Start + 1
oRng.End = oRng.End - 1
ScratchMacro2 oRng
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub
Sub ScratchMacro2(ByVal oRng2 As Range)
Documents.Add
Selection.Range.Text = oRng2.Text
End Sub





Re: macro to select text from one point to another by eugene

eugene
Tue Feb 13 11:35:01 CST 2007

Greg,

Thanks loads.

It does what exactly what I need. (Now to figure out exactly what it is
doing, so I can modify it if necessary.)

One thing I am doing away with for sure, and would not generally recommend,
is "Documents.Add." It creates a new document for each piece of text that is
copied which is not what i want. Instead, I will write to a single file.
--
eugene


"Greg Maxey" wrote:

> On Feb 13, 11:39 am, eugene <eug...@discussions.microsoft.com> wrote:
> > Hi,
> >
> > I would like to mark up a text and have a macro select the pieces of text
> > from one mark to another (eg all text between * to %), copy it and then
> > paste it into a new file.
> >
> > Any suggestions on how this can be done neatly?
> > (I can do the copy/paste part of it. But I don't know how to instruct
> > selection between the marks. I would suppose one could use find. But know how
> > to select when finding.)
> >
> > --
> > eugene
>
> Maybe something like this:
>
> Sub ScratchMacro()
> Dim oRng As Word.Range
> Set oRng = ActiveDocument.Range
> With oRng.Find
> .Text = "[\*]*%"
> .Forward = True
> .Wrap = wdFindStop
> .MatchWildcards = True
> While .Execute
> 'Clip special characters from found text
> oRng.Start = oRng.Start + 1
> oRng.End = oRng.End - 1
> ScratchMacro2 oRng
> oRng.Collapse wdCollapseEnd
> Wend
> End With
> End Sub
> Sub ScratchMacro2(ByVal oRng2 As Range)
> Documents.Add
> Selection.Range.Text = oRng2.Text
> End Sub
>
>
>
>
>

Re: macro to select text from one point to another by Greg

Greg
Tue Feb 13 14:45:58 CST 2007

On Feb 13, 12:35 pm, eugene <eug...@discussions.microsoft.com> wrote:
> Greg,
>
> Thanks loads.
>
> It does what exactly what I need. (Now to figure out exactly what it is
> doing, so I can modify it if necessary.)
>
> One thing I am doing away with for sure, and would not generally recommend,
> is "Documents.Add." It creates a new document for each piece of text that is
> copied which is not what i want. Instead, I will write to a single file.
> --
> eugene
>
>
>
> "Greg Maxey" wrote:
> > On Feb 13, 11:39 am, eugene <eug...@discussions.microsoft.com> wrote:
> > > Hi,
>
> > > I would like to mark up a text and have a macro select the pieces of text
> > > from one mark to another (eg all text between * to %), copy it and then
> > > paste it into a new file.
>
> > > Any suggestions on how this can be done neatly?
> > > (I can do the copy/paste part of it. But I don't know how to instruct
> > > selection between the marks. I would suppose one could use find. But know how
> > > to select when finding.)
>
> > > --
> > > eugene
>
> > Maybe something like this:
>
> > Sub ScratchMacro()
> > Dim oRng As Word.Range
> > Set oRng = ActiveDocument.Range
> > With oRng.Find
> > .Text = "[\*]*%"
> > .Forward = True
> > .Wrap = wdFindStop
> > .MatchWildcards = True
> > While .Execute
> > 'Clip special characters from found text
> > oRng.Start = oRng.Start + 1
> > oRng.End = oRng.End - 1
> > ScratchMacro2 oRng
> > oRng.Collapse wdCollapseEnd
> > Wend
> > End With
> > End Sub
> > Sub ScratchMacro2(ByVal oRng2 As Range)
> > Documents.Add
> > Selection.Range.Text = oRng2.Text
> > End Sub- Hide quoted text -
>
> - Show quoted text -

Then maybe something like:

Sub ScratchMacro()
Dim oRng As Word.Range
Dim oSourceDoc As Word.Document
Dim oTargetDoc As Word.Document
Set oSourceDoc = ThisDocument
Set oTargetDoc = Documents.Add
Set oRng = oSourceDoc.Range
With oRng.Find
.Text = "[\*]*%"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
While .Execute
'Clip special characters from found text
oRng.Start = oRng.Start + 1
oRng.End = oRng.End - 1
ScratchMacro2 oTargetDoc, oRng
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub
Sub ScratchMacro2(ByVal oDoc As Document, oRng2 As Range)
oDoc.Range.InsertAfter oRng2.Text & vbCr
End Sub



Re: macro to select text from one point to another by eugene

eugene
Tue Feb 13 15:12:00 CST 2007

Greg,

Thanks again. i did something similar but less elegant:
I activate an existing document and then
Selection.TypeText Text:=oRng
Selection.TypeParagraph

--
eugene


"Greg Maxey" wrote:

> On Feb 13, 12:35 pm, eugene <eug...@discussions.microsoft.com> wrote:
> > Greg,
> >
> > Thanks loads.
> >
> > It does what exactly what I need. (Now to figure out exactly what it is
> > doing, so I can modify it if necessary.)
> >
> > One thing I am doing away with for sure, and would not generally recommend,
> > is "Documents.Add." It creates a new document for each piece of text that is
> > copied which is not what i want. Instead, I will write to a single file.
> > --
> > eugene
> >
> >
> >
> > "Greg Maxey" wrote:
> > > On Feb 13, 11:39 am, eugene <eug...@discussions.microsoft.com> wrote:
> > > > Hi,
> >
> > > > I would like to mark up a text and have a macro select the pieces of text
> > > > from one mark to another (eg all text between * to %), copy it and then
> > > > paste it into a new file.
> >
> > > > Any suggestions on how this can be done neatly?
> > > > (I can do the copy/paste part of it. But I don't know how to instruct
> > > > selection between the marks. I would suppose one could use find. But know how
> > > > to select when finding.)
> >
> > > > --
> > > > eugene
> >
> > > Maybe something like this:
> >
> > > Sub ScratchMacro()
> > > Dim oRng As Word.Range
> > > Set oRng = ActiveDocument.Range
> > > With oRng.Find
> > > .Text = "[\*]*%"
> > > .Forward = True
> > > .Wrap = wdFindStop
> > > .MatchWildcards = True
> > > While .Execute
> > > 'Clip special characters from found text
> > > oRng.Start = oRng.Start + 1
> > > oRng.End = oRng.End - 1
> > > ScratchMacro2 oRng
> > > oRng.Collapse wdCollapseEnd
> > > Wend
> > > End With
> > > End Sub
> > > Sub ScratchMacro2(ByVal oRng2 As Range)
> > > Documents.Add
> > > Selection.Range.Text = oRng2.Text
> > > End Sub- Hide quoted text -
> >
> > - Show quoted text -
>
> Then maybe something like:
>
> Sub ScratchMacro()
> Dim oRng As Word.Range
> Dim oSourceDoc As Word.Document
> Dim oTargetDoc As Word.Document
> Set oSourceDoc = ThisDocument
> Set oTargetDoc = Documents.Add
> Set oRng = oSourceDoc.Range
> With oRng.Find
> .Text = "[\*]*%"
> .Forward = True
> .Wrap = wdFindStop
> .MatchWildcards = True
> While .Execute
> 'Clip special characters from found text
> oRng.Start = oRng.Start + 1
> oRng.End = oRng.End - 1
> ScratchMacro2 oTargetDoc, oRng
> oRng.Collapse wdCollapseEnd
> Wend
> End With
> End Sub
> Sub ScratchMacro2(ByVal oDoc As Document, oRng2 As Range)
> oDoc.Range.InsertAfter oRng2.Text & vbCr
> End Sub
>
>
>

Re: macro to select text from one point to another by Greg

Greg
Tue Feb 13 15:27:21 CST 2007

Ok, good. I am not so sure that my method is elegant. Someone may be along
to tell us both that we have produced sow's ears. Still if it works it
works.

Initially I thought you wanted each bit of found text in a new separated
document.

Good luck.

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


eugene wrote:
> Greg,
>
> Thanks again. i did something similar but less elegant:
> I activate an existing document and then
> Selection.TypeText Text:=oRng
> Selection.TypeParagraph
>
>
>> On Feb 13, 12:35 pm, eugene <eug...@discussions.microsoft.com> wrote:
>>> Greg,
>>>
>>> Thanks loads.
>>>
>>> It does what exactly what I need. (Now to figure out exactly what
>>> it is doing, so I can modify it if necessary.)
>>>
>>> One thing I am doing away with for sure, and would not generally
>>> recommend, is "Documents.Add." It creates a new document for each
>>> piece of text that is copied which is not what i want. Instead, I
>>> will write to a single file. --
>>> eugene
>>>
>>>
>>>
>>> "Greg Maxey" wrote:
>>>> On Feb 13, 11:39 am, eugene <eug...@discussions.microsoft.com>
>>>> wrote:
>>>>> Hi,
>>>
>>>>> I would like to mark up a text and have a macro select the pieces
>>>>> of text from one mark to another (eg all text between * to %),
>>>>> copy it and then paste it into a new file.
>>>
>>>>> Any suggestions on how this can be done neatly?
>>>>> (I can do the copy/paste part of it. But I don't know how to
>>>>> instruct selection between the marks. I would suppose one could
>>>>> use find. But know how to select when finding.)
>>>
>>>>> --
>>>>> eugene
>>>
>>>> Maybe something like this:
>>>
>>>> Sub ScratchMacro()
>>>> Dim oRng As Word.Range
>>>> Set oRng = ActiveDocument.Range
>>>> With oRng.Find
>>>> .Text = "[\*]*%"
>>>> .Forward = True
>>>> .Wrap = wdFindStop
>>>> .MatchWildcards = True
>>>> While .Execute
>>>> 'Clip special characters from found text
>>>> oRng.Start = oRng.Start + 1
>>>> oRng.End = oRng.End - 1
>>>> ScratchMacro2 oRng
>>>> oRng.Collapse wdCollapseEnd
>>>> Wend
>>>> End With
>>>> End Sub
>>>> Sub ScratchMacro2(ByVal oRng2 As Range)
>>>> Documents.Add
>>>> Selection.Range.Text = oRng2.Text
>>>> End Sub- Hide quoted text -
>>>
>>> - Show quoted text -
>>
>> Then maybe something like:
>>
>> Sub ScratchMacro()
>> Dim oRng As Word.Range
>> Dim oSourceDoc As Word.Document
>> Dim oTargetDoc As Word.Document
>> Set oSourceDoc = ThisDocument
>> Set oTargetDoc = Documents.Add
>> Set oRng = oSourceDoc.Range
>> With oRng.Find
>> .Text = "[\*]*%"
>> .Forward = True
>> .Wrap = wdFindStop
>> .MatchWildcards = True
>> While .Execute
>> 'Clip special characters from found text
>> oRng.Start = oRng.Start + 1
>> oRng.End = oRng.End - 1
>> ScratchMacro2 oTargetDoc, oRng
>> oRng.Collapse wdCollapseEnd
>> Wend
>> End With
>> End Sub
>> Sub ScratchMacro2(ByVal oDoc As Document, oRng2 As Range)
>> oDoc.Range.InsertAfter oRng2.Text & vbCr
>> End Sub