Hello from Steved

The below I would like the macro to ignore but it inputs L 0:0:0 and R 0:0:0
Please how do I tell the macro that Example is right and move onto the next
and so on, now if eample 2 is found then input L 0:0:0 above the R 22:10:30
and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in Example 4
input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12

Sub Main1()

Dim aDoc As Document
Dim SearchRng As Range
Dim AllRng As Range

Set aDoc = ActiveDocument

Set AllRng = ActiveDocument.Range
Set SearchRng = AllRng.Duplicate

Do
With SearchRng.Find
.ClearFormatting
.Text = "F [0-9]:[0-9]:[0-9]"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With

If Not SearchRng.Find.Found Then Exit Do

SearchRng.MoveStart wdParagraph, -3
SearchRng.MoveEnd wdParagraph, -3
SearchRng.Select
'Stop
If Left(SearchRng, 1) = "S" Then
SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "L" Then
SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
Else
If Left(SearchRng, 1) = "R" Then
SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
SearchRng.MoveStart wdParagraph, 3
End If
End If
End If
SearchRng.End = AllRng.End
Loop Until Not SearchRng.Find.Found

End Sub

Re: If not Found then Input by Doug

Doug
Mon Mar 03 19:29:49 PST 2008

Use

Dim myrange As Range, myrangedup As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R" Then
myrange.InsertBefore "R 0:0:0" & vbCr
End If
Loop
End With
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
Selection.Collapse wdCollapseEnd
Set myrangedup = myrange.Duplicate
myrangedup.start = myrangedup.start - 1
myrangedup.Collapse wdCollapseStart
If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L" Then
myrange.InsertBefore "L 0:0:0" & vbCr
End If
Loop
End With


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

"Steved" <Steved@discussions.microsoft.com> wrote in message
news:921E0BA8-0CEF-429F-98FF-D258F6D3E95F@microsoft.com...
> Hello from Steved
>
> The below I would like the macro to ignore but it inputs L 0:0:0 and R
> 0:0:0
> Please how do I tell the macro that Example is right and move onto the
> next
> and so on, now if eample 2 is found then input L 0:0:0 above the R
> 22:10:30
> and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in Example
> 4
> input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
> Example 1 Example 2 Example 3 Example 4
> SPR SPR SPR SPR
> L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
> R 8:0:3 F 17:10:21 F 9:11:7
> F 1:0:12
>
> Sub Main1()
>
> Dim aDoc As Document
> Dim SearchRng As Range
> Dim AllRng As Range
>
> Set aDoc = ActiveDocument
>
> Set AllRng = ActiveDocument.Range
> Set SearchRng = AllRng.Duplicate
>
> Do
> With SearchRng.Find
> .ClearFormatting
> .Text = "F [0-9]:[0-9]:[0-9]"
> .Forward = True
> .Wrap = wdFindStop
> .MatchWildcards = True
> .Execute
> End With
>
> If Not SearchRng.Find.Found Then Exit Do
>
> SearchRng.MoveStart wdParagraph, -3
> SearchRng.MoveEnd wdParagraph, -3
> SearchRng.Select
> 'Stop
> If Left(SearchRng, 1) = "S" Then
> SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
> SearchRng.MoveStart wdParagraph, 3
> Else
> If Left(SearchRng, 1) = "L" Then
> SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
> SearchRng.MoveStart wdParagraph, 3
> Else
> If Left(SearchRng, 1) = "R" Then
> SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
> SearchRng.MoveStart wdParagraph, 3
> End If
> End If
> End If
> SearchRng.End = AllRng.End
> Loop Until Not SearchRng.Find.Found
>
> End Sub
>



Re: If not Found then Input by Steved

Steved
Mon Mar 03 22:23:01 PST 2008

Hello Doug from Steved
Thankyou

Doug Please could I have in example 2 a input off "L 0:0:0" above the R
22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0" inbetween SPR
and F 0:0:0

In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your coding
and I Thankyou.

Example 1 Example 2 Example 3 Example 4
SPR SPR SPR SPR
L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
R 8:0:3 F 17:10:21 F 9:11:7
F 1:0:12





"Doug Robbins - Word MVP" wrote:

> Use
>
> Dim myrange As Range, myrangedup As Range
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
> Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
> Forward:=True, _
> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
> Set myrange = Selection.Range
> Selection.Collapse wdCollapseEnd
> Set myrangedup = myrange.Duplicate
> myrangedup.start = myrangedup.start - 1
> myrangedup.Collapse wdCollapseStart
> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R" Then
> myrange.InsertBefore "R 0:0:0" & vbCr
> End If
> Loop
> End With
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
> Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
> Forward:=True, _
> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
> Set myrange = Selection.Range
> Selection.Collapse wdCollapseEnd
> Set myrangedup = myrange.Duplicate
> myrangedup.start = myrangedup.start - 1
> myrangedup.Collapse wdCollapseStart
> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L" Then
> myrange.InsertBefore "L 0:0:0" & vbCr
> End If
> Loop
> End With
>
>
> --
> 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
>
> "Steved" <Steved@discussions.microsoft.com> wrote in message
> news:921E0BA8-0CEF-429F-98FF-D258F6D3E95F@microsoft.com...
> > Hello from Steved
> >
> > The below I would like the macro to ignore but it inputs L 0:0:0 and R
> > 0:0:0
> > Please how do I tell the macro that Example is right and move onto the
> > next
> > and so on, now if eample 2 is found then input L 0:0:0 above the R
> > 22:10:30
> > and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in Example
> > 4
> > input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
> > Example 1 Example 2 Example 3 Example 4
> > SPR SPR SPR SPR
> > L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
> > R 8:0:3 F 17:10:21 F 9:11:7
> > F 1:0:12
> >
> > Sub Main1()
> >
> > Dim aDoc As Document
> > Dim SearchRng As Range
> > Dim AllRng As Range
> >
> > Set aDoc = ActiveDocument
> >
> > Set AllRng = ActiveDocument.Range
> > Set SearchRng = AllRng.Duplicate
> >
> > Do
> > With SearchRng.Find
> > .ClearFormatting
> > .Text = "F [0-9]:[0-9]:[0-9]"
> > .Forward = True
> > .Wrap = wdFindStop
> > .MatchWildcards = True
> > .Execute
> > End With
> >
> > If Not SearchRng.Find.Found Then Exit Do
> >
> > SearchRng.MoveStart wdParagraph, -3
> > SearchRng.MoveEnd wdParagraph, -3
> > SearchRng.Select
> > 'Stop
> > If Left(SearchRng, 1) = "S" Then
> > SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
> > SearchRng.MoveStart wdParagraph, 3
> > Else
> > If Left(SearchRng, 1) = "L" Then
> > SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
> > SearchRng.MoveStart wdParagraph, 3
> > Else
> > If Left(SearchRng, 1) = "R" Then
> > SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
> > SearchRng.MoveStart wdParagraph, 3
> > End If
> > End If
> > End If
> > SearchRng.End = AllRng.End
> > Loop Until Not SearchRng.Find.Found
> >
> > End Sub
> >
>
>
>

Re: If not Found then Input by Doug

Doug
Tue Mar 04 02:38:56 PST 2008

That is exactly what the code does when I run it.

Starting with a document containing:

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
F 9:11:7¶
SPR¶
F 0:0:0¶

after running the macro, I get

SPR¶
L 6:0:1¶
R 8:0:3¶
F 1:0:12¶
SPR¶
L 0:0:0¶
R 22:10:30¶
F 17:10:21¶
SPR¶
L 12:19:1¶
R 0:0:0¶
F 9:11:7¶
SPR¶
L 0:0:0¶
R 0:0:0¶
F 0:0:0¶

Are you sure that each item is in a separate paragraph as indicated by the ¶
that I have inserted above.
--
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

"Steved" <Steved@discussions.microsoft.com> wrote in message
news:A8709075-3A8E-429B-A397-463E85D8C9A6@microsoft.com...
> Hello Doug from Steved
> Thankyou
>
> Doug Please could I have in example 2 a input off "L 0:0:0" above the R
> 22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0" inbetween
> SPR
> and F 0:0:0
>
> In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your
> coding
> and I Thankyou.
>
> Example 1 Example 2 Example 3 Example 4
> SPR SPR SPR SPR
> L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
> R 8:0:3 F 17:10:21 F 9:11:7
> F 1:0:12
>
>
>
>
>
> "Doug Robbins - Word MVP" wrote:
>
>> Use
>>
>> Dim myrange As Range, myrangedup As Range
>> Selection.HomeKey wdStory
>> Selection.Find.ClearFormatting
>> With Selection.Find
>> Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
>> Forward:=True, _
>> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
>> True
>> Set myrange = Selection.Range
>> Selection.Collapse wdCollapseEnd
>> Set myrangedup = myrange.Duplicate
>> myrangedup.start = myrangedup.start - 1
>> myrangedup.Collapse wdCollapseStart
>> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R" Then
>> myrange.InsertBefore "R 0:0:0" & vbCr
>> End If
>> Loop
>> End With
>> Selection.HomeKey wdStory
>> Selection.Find.ClearFormatting
>> With Selection.Find
>> Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
>> Forward:=True, _
>> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
>> True
>> Set myrange = Selection.Range
>> Selection.Collapse wdCollapseEnd
>> Set myrangedup = myrange.Duplicate
>> myrangedup.start = myrangedup.start - 1
>> myrangedup.Collapse wdCollapseStart
>> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L" Then
>> myrange.InsertBefore "L 0:0:0" & vbCr
>> End If
>> Loop
>> End With
>>
>>
>> --
>> 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
>>
>> "Steved" <Steved@discussions.microsoft.com> wrote in message
>> news:921E0BA8-0CEF-429F-98FF-D258F6D3E95F@microsoft.com...
>> > Hello from Steved
>> >
>> > The below I would like the macro to ignore but it inputs L 0:0:0 and R
>> > 0:0:0
>> > Please how do I tell the macro that Example is right and move onto the
>> > next
>> > and so on, now if eample 2 is found then input L 0:0:0 above the R
>> > 22:10:30
>> > and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in
>> > Example
>> > 4
>> > input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
>> > Example 1 Example 2 Example 3 Example 4
>> > SPR SPR SPR SPR
>> > L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
>> > R 8:0:3 F 17:10:21 F 9:11:7
>> > F 1:0:12
>> >
>> > Sub Main1()
>> >
>> > Dim aDoc As Document
>> > Dim SearchRng As Range
>> > Dim AllRng As Range
>> >
>> > Set aDoc = ActiveDocument
>> >
>> > Set AllRng = ActiveDocument.Range
>> > Set SearchRng = AllRng.Duplicate
>> >
>> > Do
>> > With SearchRng.Find
>> > .ClearFormatting
>> > .Text = "F [0-9]:[0-9]:[0-9]"
>> > .Forward = True
>> > .Wrap = wdFindStop
>> > .MatchWildcards = True
>> > .Execute
>> > End With
>> >
>> > If Not SearchRng.Find.Found Then Exit Do
>> >
>> > SearchRng.MoveStart wdParagraph, -3
>> > SearchRng.MoveEnd wdParagraph, -3
>> > SearchRng.Select
>> > 'Stop
>> > If Left(SearchRng, 1) = "S" Then
>> > SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
>> > SearchRng.MoveStart wdParagraph, 3
>> > Else
>> > If Left(SearchRng, 1) = "L" Then
>> > SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
>> > SearchRng.MoveStart wdParagraph, 3
>> > Else
>> > If Left(SearchRng, 1) = "R" Then
>> > SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
>> > SearchRng.MoveStart wdParagraph, 3
>> > End If
>> > End If
>> > End If
>> > SearchRng.End = AllRng.End
>> > Loop Until Not SearchRng.Find.Found
>> >
>> > End Sub
>> >
>>
>>
>>



Re: If not Found then Input by Steved

Steved
Tue Mar 04 12:47:01 PST 2008

Hello Doug from Steved.

It's perfect I thankyou.

Please I would like to explain what had happened.

Because off you code and I like to learn what you code does I run it in
"Step Mode".
The first 3 it had done was fine then on the 4th the R 0:0:0 was missing you
code inputted it which is what it is supposed to do but when it found L 0:0:0
missing it ignored it by not inserting L 0:0:0 and went onto the next one,
however when I run your macro ( not step mode ) it did inputted it.

ps Yes Doug I should have run the macro, I'm very sorry for wasting your
time, as I should have know'n better.

Thankyou for your good work.

"Doug Robbins - Word MVP" wrote:

> That is exactly what the code does when I run it.
>
> Starting with a document containing:
>
> SPR¶
> L 6:0:1¶
> R 8:0:3¶
> F 1:0:12¶
> SPR¶
> R 22:10:30¶
> F 17:10:21¶
> SPR¶
> L 12:19:1¶
> F 9:11:7¶
> SPR¶
> F 0:0:0¶
>
> after running the macro, I get
>
> SPR¶
> L 6:0:1¶
> R 8:0:3¶
> F 1:0:12¶
> SPR¶
> L 0:0:0¶
> R 22:10:30¶
> F 17:10:21¶
> SPR¶
> L 12:19:1¶
> R 0:0:0¶
> F 9:11:7¶
> SPR¶
> L 0:0:0¶
> R 0:0:0¶
> F 0:0:0¶
>
> Are you sure that each item is in a separate paragraph as indicated by the ¶
> that I have inserted above.
> --
> 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
>
> "Steved" <Steved@discussions.microsoft.com> wrote in message
> news:A8709075-3A8E-429B-A397-463E85D8C9A6@microsoft.com...
> > Hello Doug from Steved
> > Thankyou
> >
> > Doug Please could I have in example 2 a input off "L 0:0:0" above the R
> > 22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0" inbetween
> > SPR
> > and F 0:0:0
> >
> > In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your
> > coding
> > and I Thankyou.
> >
> > Example 1 Example 2 Example 3 Example 4
> > SPR SPR SPR SPR
> > L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
> > R 8:0:3 F 17:10:21 F 9:11:7
> > F 1:0:12
> >
> >
> >
> >
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> Use
> >>
> >> Dim myrange As Range, myrangedup As Range
> >> Selection.HomeKey wdStory
> >> Selection.Find.ClearFormatting
> >> With Selection.Find
> >> Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
> >> Forward:=True, _
> >> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
> >> True
> >> Set myrange = Selection.Range
> >> Selection.Collapse wdCollapseEnd
> >> Set myrangedup = myrange.Duplicate
> >> myrangedup.start = myrangedup.start - 1
> >> myrangedup.Collapse wdCollapseStart
> >> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R" Then
> >> myrange.InsertBefore "R 0:0:0" & vbCr
> >> End If
> >> Loop
> >> End With
> >> Selection.HomeKey wdStory
> >> Selection.Find.ClearFormatting
> >> With Selection.Find
> >> Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
> >> Forward:=True, _
> >> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
> >> True
> >> Set myrange = Selection.Range
> >> Selection.Collapse wdCollapseEnd
> >> Set myrangedup = myrange.Duplicate
> >> myrangedup.start = myrangedup.start - 1
> >> myrangedup.Collapse wdCollapseStart
> >> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L" Then
> >> myrange.InsertBefore "L 0:0:0" & vbCr
> >> End If
> >> Loop
> >> End With
> >>
> >>
> >> --
> >> 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
> >>
> >> "Steved" <Steved@discussions.microsoft.com> wrote in message
> >> news:921E0BA8-0CEF-429F-98FF-D258F6D3E95F@microsoft.com...
> >> > Hello from Steved
> >> >
> >> > The below I would like the macro to ignore but it inputs L 0:0:0 and R
> >> > 0:0:0
> >> > Please how do I tell the macro that Example is right and move onto the
> >> > next
> >> > and so on, now if eample 2 is found then input L 0:0:0 above the R
> >> > 22:10:30
> >> > and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in
> >> > Example
> >> > 4
> >> > input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
> >> > Example 1 Example 2 Example 3 Example 4
> >> > SPR SPR SPR SPR
> >> > L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
> >> > R 8:0:3 F 17:10:21 F 9:11:7
> >> > F 1:0:12
> >> >
> >> > Sub Main1()
> >> >
> >> > Dim aDoc As Document
> >> > Dim SearchRng As Range
> >> > Dim AllRng As Range
> >> >
> >> > Set aDoc = ActiveDocument
> >> >
> >> > Set AllRng = ActiveDocument.Range
> >> > Set SearchRng = AllRng.Duplicate
> >> >
> >> > Do
> >> > With SearchRng.Find
> >> > .ClearFormatting
> >> > .Text = "F [0-9]:[0-9]:[0-9]"
> >> > .Forward = True
> >> > .Wrap = wdFindStop
> >> > .MatchWildcards = True
> >> > .Execute
> >> > End With
> >> >
> >> > If Not SearchRng.Find.Found Then Exit Do
> >> >
> >> > SearchRng.MoveStart wdParagraph, -3
> >> > SearchRng.MoveEnd wdParagraph, -3
> >> > SearchRng.Select
> >> > 'Stop
> >> > If Left(SearchRng, 1) = "S" Then
> >> > SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
> >> > SearchRng.MoveStart wdParagraph, 3
> >> > Else
> >> > If Left(SearchRng, 1) = "L" Then
> >> > SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
> >> > SearchRng.MoveStart wdParagraph, 3
> >> > Else
> >> > If Left(SearchRng, 1) = "R" Then
> >> > SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
> >> > SearchRng.MoveStart wdParagraph, 3
> >> > End If
> >> > End If
> >> > End If
> >> > SearchRng.End = AllRng.End
> >> > Loop Until Not SearchRng.Find.Found
> >> >
> >> > End Sub
> >> >
> >>
> >>
> >>
>
>
>

Re: If not Found then Input by Doug

Doug
Fri Mar 07 03:58:43 PST 2008

No problem. It was really your time that you wasted.

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

"Steved" <Steved@discussions.microsoft.com> wrote in message
news:C6A7154E-AD86-42D2-A2D9-009ACA7DDA60@microsoft.com...
> Hello Doug from Steved.
>
> It's perfect I thankyou.
>
> Please I would like to explain what had happened.
>
> Because off you code and I like to learn what you code does I run it in
> "Step Mode".
> The first 3 it had done was fine then on the 4th the R 0:0:0 was missing
> you
> code inputted it which is what it is supposed to do but when it found L
> 0:0:0
> missing it ignored it by not inserting L 0:0:0 and went onto the next one,
> however when I run your macro ( not step mode ) it did inputted it.
>
> ps Yes Doug I should have run the macro, I'm very sorry for wasting your
> time, as I should have know'n better.
>
> Thankyou for your good work.
>
> "Doug Robbins - Word MVP" wrote:
>
>> That is exactly what the code does when I run it.
>>
>> Starting with a document containing:
>>
>> SPR¶
>> L 6:0:1¶
>> R 8:0:3¶
>> F 1:0:12¶
>> SPR¶
>> R 22:10:30¶
>> F 17:10:21¶
>> SPR¶
>> L 12:19:1¶
>> F 9:11:7¶
>> SPR¶
>> F 0:0:0¶
>>
>> after running the macro, I get
>>
>> SPR¶
>> L 6:0:1¶
>> R 8:0:3¶
>> F 1:0:12¶
>> SPR¶
>> L 0:0:0¶
>> R 22:10:30¶
>> F 17:10:21¶
>> SPR¶
>> L 12:19:1¶
>> R 0:0:0¶
>> F 9:11:7¶
>> SPR¶
>> L 0:0:0¶
>> R 0:0:0¶
>> F 0:0:0¶
>>
>> Are you sure that each item is in a separate paragraph as indicated by
>> the ¶
>> that I have inserted above.
>> --
>> 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
>>
>> "Steved" <Steved@discussions.microsoft.com> wrote in message
>> news:A8709075-3A8E-429B-A397-463E85D8C9A6@microsoft.com...
>> > Hello Doug from Steved
>> > Thankyou
>> >
>> > Doug Please could I have in example 2 a input off "L 0:0:0" above the R
>> > 22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0"
>> > inbetween
>> > SPR
>> > and F 0:0:0
>> >
>> > In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your
>> > coding
>> > and I Thankyou.
>> >
>> > Example 1 Example 2 Example 3 Example 4
>> > SPR SPR SPR SPR
>> > L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
>> > R 8:0:3 F 17:10:21 F 9:11:7
>> > F 1:0:12
>> >
>> >
>> >
>> >
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> Use
>> >>
>> >> Dim myrange As Range, myrangedup As Range
>> >> Selection.HomeKey wdStory
>> >> Selection.Find.ClearFormatting
>> >> With Selection.Find
>> >> Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
>> >> Forward:=True, _
>> >> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
>> >> True
>> >> Set myrange = Selection.Range
>> >> Selection.Collapse wdCollapseEnd
>> >> Set myrangedup = myrange.Duplicate
>> >> myrangedup.start = myrangedup.start - 1
>> >> myrangedup.Collapse wdCollapseStart
>> >> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R"
>> >> Then
>> >> myrange.InsertBefore "R 0:0:0" & vbCr
>> >> End If
>> >> Loop
>> >> End With
>> >> Selection.HomeKey wdStory
>> >> Selection.Find.ClearFormatting
>> >> With Selection.Find
>> >> Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
>> >> Forward:=True, _
>> >> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
>> >> True
>> >> Set myrange = Selection.Range
>> >> Selection.Collapse wdCollapseEnd
>> >> Set myrangedup = myrange.Duplicate
>> >> myrangedup.start = myrangedup.start - 1
>> >> myrangedup.Collapse wdCollapseStart
>> >> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L"
>> >> Then
>> >> myrange.InsertBefore "L 0:0:0" & vbCr
>> >> End If
>> >> Loop
>> >> End With
>> >>
>> >>
>> >> --
>> >> 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
>> >>
>> >> "Steved" <Steved@discussions.microsoft.com> wrote in message
>> >> news:921E0BA8-0CEF-429F-98FF-D258F6D3E95F@microsoft.com...
>> >> > Hello from Steved
>> >> >
>> >> > The below I would like the macro to ignore but it inputs L 0:0:0 and
>> >> > R
>> >> > 0:0:0
>> >> > Please how do I tell the macro that Example is right and move onto
>> >> > the
>> >> > next
>> >> > and so on, now if eample 2 is found then input L 0:0:0 above the R
>> >> > 22:10:30
>> >> > and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in
>> >> > Example
>> >> > 4
>> >> > input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
>> >> > Example 1 Example 2 Example 3 Example 4
>> >> > SPR SPR SPR SPR
>> >> > L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
>> >> > R 8:0:3 F 17:10:21 F 9:11:7
>> >> > F 1:0:12
>> >> >
>> >> > Sub Main1()
>> >> >
>> >> > Dim aDoc As Document
>> >> > Dim SearchRng As Range
>> >> > Dim AllRng As Range
>> >> >
>> >> > Set aDoc = ActiveDocument
>> >> >
>> >> > Set AllRng = ActiveDocument.Range
>> >> > Set SearchRng = AllRng.Duplicate
>> >> >
>> >> > Do
>> >> > With SearchRng.Find
>> >> > .ClearFormatting
>> >> > .Text = "F [0-9]:[0-9]:[0-9]"
>> >> > .Forward = True
>> >> > .Wrap = wdFindStop
>> >> > .MatchWildcards = True
>> >> > .Execute
>> >> > End With
>> >> >
>> >> > If Not SearchRng.Find.Found Then Exit Do
>> >> >
>> >> > SearchRng.MoveStart wdParagraph, -3
>> >> > SearchRng.MoveEnd wdParagraph, -3
>> >> > SearchRng.Select
>> >> > 'Stop
>> >> > If Left(SearchRng, 1) = "S" Then
>> >> > SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
>> >> > SearchRng.MoveStart wdParagraph, 3
>> >> > Else
>> >> > If Left(SearchRng, 1) = "L" Then
>> >> > SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
>> >> > SearchRng.MoveStart wdParagraph, 3
>> >> > Else
>> >> > If Left(SearchRng, 1) = "R" Then
>> >> > SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
>> >> > SearchRng.MoveStart wdParagraph, 3
>> >> > End If
>> >> > End If
>> >> > End If
>> >> > SearchRng.End = AllRng.End
>> >> > Loop Until Not SearchRng.Find.Found
>> >> >
>> >> > End Sub
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>



Re: If not Found then Input by Steved

Steved
Fri Mar 07 19:05:00 PST 2008

Thankyou Doug

"Doug Robbins - Word MVP" wrote:

> No problem. It was really your time that you wasted.
>
> --
> 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
>
> "Steved" <Steved@discussions.microsoft.com> wrote in message
> news:C6A7154E-AD86-42D2-A2D9-009ACA7DDA60@microsoft.com...
> > Hello Doug from Steved.
> >
> > It's perfect I thankyou.
> >
> > Please I would like to explain what had happened.
> >
> > Because off you code and I like to learn what you code does I run it in
> > "Step Mode".
> > The first 3 it had done was fine then on the 4th the R 0:0:0 was missing
> > you
> > code inputted it which is what it is supposed to do but when it found L
> > 0:0:0
> > missing it ignored it by not inserting L 0:0:0 and went onto the next one,
> > however when I run your macro ( not step mode ) it did inputted it.
> >
> > ps Yes Doug I should have run the macro, I'm very sorry for wasting your
> > time, as I should have know'n better.
> >
> > Thankyou for your good work.
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> That is exactly what the code does when I run it.
> >>
> >> Starting with a document containing:
> >>
> >> SPR¶
> >> L 6:0:1¶
> >> R 8:0:3¶
> >> F 1:0:12¶
> >> SPR¶
> >> R 22:10:30¶
> >> F 17:10:21¶
> >> SPR¶
> >> L 12:19:1¶
> >> F 9:11:7¶
> >> SPR¶
> >> F 0:0:0¶
> >>
> >> after running the macro, I get
> >>
> >> SPR¶
> >> L 6:0:1¶
> >> R 8:0:3¶
> >> F 1:0:12¶
> >> SPR¶
> >> L 0:0:0¶
> >> R 22:10:30¶
> >> F 17:10:21¶
> >> SPR¶
> >> L 12:19:1¶
> >> R 0:0:0¶
> >> F 9:11:7¶
> >> SPR¶
> >> L 0:0:0¶
> >> R 0:0:0¶
> >> F 0:0:0¶
> >>
> >> Are you sure that each item is in a separate paragraph as indicated by
> >> the ¶
> >> that I have inserted above.
> >> --
> >> 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
> >>
> >> "Steved" <Steved@discussions.microsoft.com> wrote in message
> >> news:A8709075-3A8E-429B-A397-463E85D8C9A6@microsoft.com...
> >> > Hello Doug from Steved
> >> > Thankyou
> >> >
> >> > Doug Please could I have in example 2 a input off "L 0:0:0" above the R
> >> > 22:10:30 and in example 4 an input off "L 0:0:0" and "R 0:0:0"
> >> > inbetween
> >> > SPR
> >> > and F 0:0:0
> >> >
> >> > In Example 3 it is inputing "R 0:0:0" after the L 12:19:1 As per your
> >> > coding
> >> > and I Thankyou.
> >> >
> >> > Example 1 Example 2 Example 3 Example 4
> >> > SPR SPR SPR SPR
> >> > L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
> >> > R 8:0:3 F 17:10:21 F 9:11:7
> >> > F 1:0:12
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > "Doug Robbins - Word MVP" wrote:
> >> >
> >> >> Use
> >> >>
> >> >> Dim myrange As Range, myrangedup As Range
> >> >> Selection.HomeKey wdStory
> >> >> Selection.Find.ClearFormatting
> >> >> With Selection.Find
> >> >> Do While .Execute(findText:="F [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
> >> >> Forward:=True, _
> >> >> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
> >> >> True
> >> >> Set myrange = Selection.Range
> >> >> Selection.Collapse wdCollapseEnd
> >> >> Set myrangedup = myrange.Duplicate
> >> >> myrangedup.start = myrangedup.start - 1
> >> >> myrangedup.Collapse wdCollapseStart
> >> >> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "R"
> >> >> Then
> >> >> myrange.InsertBefore "R 0:0:0" & vbCr
> >> >> End If
> >> >> Loop
> >> >> End With
> >> >> Selection.HomeKey wdStory
> >> >> Selection.Find.ClearFormatting
> >> >> With Selection.Find
> >> >> Do While .Execute(findText:="R [0-9]{1,}:[0-9]{1,}:[0-9]{1,}",
> >> >> Forward:=True, _
> >> >> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
> >> >> True
> >> >> Set myrange = Selection.Range
> >> >> Selection.Collapse wdCollapseEnd
> >> >> Set myrangedup = myrange.Duplicate
> >> >> myrangedup.start = myrangedup.start - 1
> >> >> myrangedup.Collapse wdCollapseStart
> >> >> If Left(myrangedup.Paragraphs(1).Range.Text, 1) <> "L"
> >> >> Then
> >> >> myrange.InsertBefore "L 0:0:0" & vbCr
> >> >> End If
> >> >> Loop
> >> >> End With
> >> >>
> >> >>
> >> >> --
> >> >> 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
> >> >>
> >> >> "Steved" <Steved@discussions.microsoft.com> wrote in message
> >> >> news:921E0BA8-0CEF-429F-98FF-D258F6D3E95F@microsoft.com...
> >> >> > Hello from Steved
> >> >> >
> >> >> > The below I would like the macro to ignore but it inputs L 0:0:0 and
> >> >> > R
> >> >> > 0:0:0
> >> >> > Please how do I tell the macro that Example is right and move onto
> >> >> > the
> >> >> > next
> >> >> > and so on, now if eample 2 is found then input L 0:0:0 above the R
> >> >> > 22:10:30
> >> >> > and in Example 3 input R 0:0:0 below the L 12:19:1 and finally in
> >> >> > Example
> >> >> > 4
> >> >> > input L 0:0:0 and L 0:0:0 The macro is below the Examples. Thankyou.
> >> >> > Example 1 Example 2 Example 3 Example 4
> >> >> > SPR SPR SPR SPR
> >> >> > L 6:0:1 R 22:10:30 L 12:19:1 F 0:0:0
> >> >> > R 8:0:3 F 17:10:21 F 9:11:7
> >> >> > F 1:0:12
> >> >> >
> >> >> > Sub Main1()
> >> >> >
> >> >> > Dim aDoc As Document
> >> >> > Dim SearchRng As Range
> >> >> > Dim AllRng As Range
> >> >> >
> >> >> > Set aDoc = ActiveDocument
> >> >> >
> >> >> > Set AllRng = ActiveDocument.Range
> >> >> > Set SearchRng = AllRng.Duplicate
> >> >> >
> >> >> > Do
> >> >> > With SearchRng.Find
> >> >> > .ClearFormatting
> >> >> > .Text = "F [0-9]:[0-9]:[0-9]"
> >> >> > .Forward = True
> >> >> > .Wrap = wdFindStop
> >> >> > .MatchWildcards = True
> >> >> > .Execute
> >> >> > End With
> >> >> >
> >> >> > If Not SearchRng.Find.Found Then Exit Do
> >> >> >
> >> >> > SearchRng.MoveStart wdParagraph, -3
> >> >> > SearchRng.MoveEnd wdParagraph, -3
> >> >> > SearchRng.Select
> >> >> > 'Stop
> >> >> > If Left(SearchRng, 1) = "S" Then
> >> >> > SearchRng.InsertAfter "L 0:0:0" & vbCr & "R 0:0:0" & vbCr
> >> >> > SearchRng.MoveStart wdParagraph, 3
> >> >> > Else
> >> >> > If Left(SearchRng, 1) = "L" Then
> >> >> > SearchRng.InsertAfter "R [0-9]:[0-9]:[0-9]" & vbCr
> >> >> > SearchRng.MoveStart wdParagraph, 3
> >> >> > Else
> >> >> > If Left(SearchRng, 1) = "R" Then
> >> >> > SearchRng.InsertBefore "L [0-0]:[0-9]:[0-9]" & vbCr
> >> >> > SearchRng.MoveStart wdParagraph, 3
> >> >> > End If
> >> >> > End If
> >> >> > End If
> >> >> > SearchRng.End = AllRng.End
> >> >> > Loop Until Not SearchRng.Find.Found
> >> >> >
> >> >> > End Sub
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>