Checking via VBA whether current selection is at the very beginningof the paragraph or not?

A

andreas

Dear Experts:

is it possible to check whether the current selection/insertion point
is right at the beginning of the paragraph or if there are more
characters to the left of the selection?


Code Snippet
.......
If f.Type = wdFieldStyleRef And InStr(UCase(f.Code), "N") > 0 Then
f.Select
Selection.MoveLeft

Now the macro should check whether the selection/insertion point is
right at the beginning of the paragraph, If so, the macro would go on
with "then ... else ... End If"

Help is much appreciated. Thank you very much in advance. Regards,
Andreas
 
D

Doug Robbins - Word MVP

Use

Dim mrange as Range

If f.Type = wdFieldStyleRef And InStr(UCase(f.Code), "N") > 0 Then
f.Select
End If
Set mrange = Selection.Paragraphs(1).Range
mrange.Collapse wdCollapseStart

mrange will then be the start of the paragraph.
--
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
 
J

Jonathan West

andreas said:
Dear Experts:

is it possible to check whether the current selection/insertion point
is right at the beginning of the paragraph or if there are more
characters to the left of the selection?


Code Snippet
......
If f.Type = wdFieldStyleRef And InStr(UCase(f.Code), "N") > 0 Then
f.Select
Selection.MoveLeft

Now the macro should check whether the selection/insertion point is
right at the beginning of the paragraph, If so, the macro would go on
with "then ... else ... End If"

Help is much appreciated. Thank you very much in advance. Regards,
Andreas

If Selection.Left > Selection.Paragraphs(1).Range.Left Then
'Selection is not at start of paragraph, move it
Selection.Left Selection.Paragraphs(1).Range.Left
End If
 
A

andreas

If Selection.Left > Selection.Paragraphs(1).Range.Left Then
  'Selection is not at start of paragraph, move it
  Selection.Left  Selection.Paragraphs(1).Range.Left
End If

--
Regards
Jonathan West - Word MVPwww.intelligentdocuments.co.uk
Please reply to the newsgroup- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Dear Jonathan.

ok, it works fine. Thank you very much. Regards, Andreas
 
A

andreas

Use

Dim mrange as Range

If f.Type = wdFieldStyleRef And InStr(UCase(f.Code), "N") > 0 Then
    f.Select
End If
Set mrange = Selection.Paragraphs(1).Range
mrange.Collapse wdCollapseStart

mrange will then be the start of the paragraph.
--
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










- Zitierten Text anzeigen -

Dear Doug,

thanks for the quick answer. Taking from what your answer is, you must
have misunderstood me. Although your answer is correct in itself, my
problem was solved with Jonathan's answer. Thank you so much for your
professional help. Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top