I need to find a character then select to the end of the current line,
but not select anything in front of the character. Later I will make
a font change but I can work that out...

Im working with:

With Selection.Find
.Text = myCharacter
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

Selection.Find.Execute

Selection.Select

Selection.Expand Unit:=wdWord
Selection.Select

Im trying different things in the WdUnits items and using the expand
function but I am stumped at this point.

Any help will be appreciated

Robert

Re: expand to end of line by Greg

Greg
Tue Feb 13 15:46:22 CST 2007

Robert,

Try:
Sub ScratchMacro()
Dim oRng As Word.Range
Dim myCharacter As String
Set oRng = ActiveDocument.Range
myCharacter = "a"
With oRng.Find
.Text = myCharacter
.Execute
If .Found Then
With oRng
.MoveEndUntil vbCr
'.MoveEnd wdCharacter, 1 'Unstet and include this line to include the
ending paragraph mark
.Select
End With
End If
End With
End Sub



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


Robert H wrote:
> I need to find a character then select to the end of the current line,
> but not select anything in front of the character. Later I will make
> a font change but I can work that out...
>
> Im working with:
>
> With Selection.Find
> .Text = myCharacter
> .Forward = True
> .Wrap = wdFindAsk
> .Format = True
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
>
> Selection.Find.Execute
>
> Selection.Select
>
> Selection.Expand Unit:=wdWord
> Selection.Select
>
> Im trying different things in the WdUnits items and using the expand
> function but I am stumped at this point.
>
> Any help will be appreciated
>
> Robert



Re: expand to end of line by Helmut

Helmut
Tue Feb 13 15:47:40 CST 2007

Hi Robert,

this one will find the first "M" or "m" in
the docuemnt's main story
and select form it to the end of line:

Sub Test77709()
Dim rng As Range
Set rng = ActiveDocument.Range
With rng.Find
.Text = "M"
If .Execute Then
rng.End = rng.Bookmarks("\Line").End
rng.Select
End If
End With
End Sub

You may want to search for the next "M" in the line
the insertion point is in and, if found, select
to the rest of the line, which is a somewhat different story.


HTH nevertheless,

it is the rng.Bookmarks("\Line").End
which you can put to good use.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


Re: expand to end of line by Robert

Robert
Tue Feb 13 21:53:43 CST 2007

Thanks to you both I will try those out in the morning.
Robert


Re: expand to end of line by Greg

Greg
Wed Feb 14 03:45:27 CST 2007

Helmut,

I didn't think of that, but when I checked your method in Word2007 I noticed
that it returns a runtime error if the cursor is not in a line that contains
an "M" when the code is run. I don't know if this happens in earlier
versions or not.


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

"Helmut Weber" <nbhymsjxdgcn@mailinator.com> wrote in message
news:l1c4t29js1cspfg66tu2mk9anu1vgj1s89@4ax.com...
> Hi Robert,
>
> this one will find the first "M" or "m" in
> the docuemnt's main story
> and select form it to the end of line:
>
> Sub Test77709()
> Dim rng As Range
> Set rng = ActiveDocument.Range
> With rng.Find
> .Text = "M"
> If .Execute Then
> rng.End = rng.Bookmarks("\Line").End
> rng.Select
> End If
> End With
> End Sub
>
> You may want to search for the next "M" in the line
> the insertion point is in and, if found, select
> to the rest of the line, which is a somewhat different story.
>
>
> HTH nevertheless,
>
> it is the rng.Bookmarks("\Line").End
> which you can put to good use.
>
>
> --
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP WordVBA
>
> Win XP, Office 2003
> "red.sys" & Chr$(64) & "t-online.de"
>



Re: expand to end of line by HelmutWeber

HelmutWeber
Wed Feb 14 07:31:30 CST 2007

Hi Greg,

> I didn't think of that, but when I checked your method in Word2007 I noticed
> that it returns a runtime error if the cursor is not in a line that contains
> an "M" when the code is run. I don't know if this happens in earlier
> versions or not.

happens with 2002 as well.
An additional select will cure the problem,
which doesn't mean that I aöready understand what's going on.

Sub Test77709()
Dim rng As Range
Set rng = ActiveDocument.Range
With rng.Find
.Text = "M"
If .Execute Then
rng.Select ' <<<
rng.End = rng.Bookmarks("\Line").End
rng.Select
End If
End With
End Sub

--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000 (german versions)



Re: expand to end of line by Greg

Greg
Wed Feb 14 13:23:35 CST 2007

Yes that works. I think I would use your method now over mine as it works
and mine doesn't. I only tested on a short sentence with a ending paragraph
mark :-(

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


Helmut Weber wrote:
> Hi Greg,
>
>> I didn't think of that, but when I checked your method in Word2007 I
>> noticed that it returns a runtime error if the cursor is not in a
>> line that contains an "M" when the code is run. I don't know if
>> this happens in earlier versions or not.
>
> happens with 2002 as well.
> An additional select will cure the problem,
> which doesn't mean that I aöready understand what's going on.
>
> Sub Test77709()
> Dim rng As Range
> Set rng = ActiveDocument.Range
> With rng.Find
> .Text = "M"
> If .Execute Then
> rng.Select ' <<<
> rng.End = rng.Bookmarks("\Line").End
> rng.Select
> End If
> End With
> End Sub



Re: expand to end of line by Robert

Robert
Thu Feb 15 09:56:13 CST 2007

I was able to incorporate
rng.End =3D rng.Bookmarks("\Line").End
Into my code and it works great. thank, both of you for helping me
with this!

Robert

On Feb 14, 2:23 pm, "Greg Maxey" <gma...@mvps.oSCARrOMEOgOLF> wrote:
> Yes that works. I think I would use your method now over mine as it works
> and mine doesn't. I only tested on a short sentence with a ending paragr=
aph
> mark :-(
>
> --
> Greg Maxey/Word MVP
> See:http://gregmaxey.mvps.org/word_tips.htm
> For some helpful tips using Word.
>
> Helmut Weber wrote:
> > Hi Greg,
>
> >> I didn't think of that, but when I checked your method in Word2007 I
> >> noticed that it returns a runtime error if the cursor is not in a
> >> line that contains an "M" when the code is run. I don't know if
> >> this happens in earlier versions or not.
>
> > happens with 2002 as well.
> > An additional select will cure the problem,
> > which doesn't mean that I a=F6ready understand what's going on.
>
> > Sub Test77709()
> > Dim rng As Range
> > Set rng =3D ActiveDocument.Range
> > With rng.Find
> > .Text =3D "M"
> > If .Execute Then
> > rng.Select ' <<<
> > rng.End =3D rng.Bookmarks("\Line").End
> > rng.Select
> > End If
> > End With
> > End Sub