Selecting a paragraph

F

Francis Hookham

I need to add '<B>' at the beginning and '</B>' at the end of the particular
paragraph then move to the beginning of the next paragraph. The following
works if the insertion point is at the beginning of the paragraph but falls
down if not.

I have tried various key combinations to try to get to the beginning of the
paragraph but if the insertion point is already there they fall down too.
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend

Please help

Francis Hookham

Sub htmlBold()
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.TypeText Text:="<B>"
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="</B>"
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
 
D

Doug Robbins - Word MVP

Use:

Dim myrange As Range
Set myrange = Selection.Paragraphs(1).Range
myrange.Select
Selection.Collapse wdCollapseEnd
With myrange
.End = .End - 1
.InsertBefore "<B>"
.InsertAfter "</B>"
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
 
S

Shasur

You can try with the following

Sub Make_Each_PAra_Bold()

Dim oPara As Paragraph

Set oPara = Selection.Paragraphs(1)
oPara.Range.Select
Selection.MoveLeft wdCharacter, 1, wdExtend
oPara.Range.End = oPara.Range.End - 1
Selection.InsertBefore "<B>"
Selection.InsertAfter "</B>"
Selection.MoveDown wdParagraph, 1, wdMove

End Sub

Cheers
 
F

Francis Hookham

Many thanks Doug and Shasur

now I shall have to toss a coin to choose - both work exactly as I wanted
and I have yet again learned a lot

Francis
 
G

Gordon Bentley-Mix

Francis,

I'm a bit late with my reply, but this sort of slipped off my radar.

IMHO, I'd use Doug's solution. No offense intended to Shasur, but in any
solution if you can at all avoid using the Selection object - and especially
moving it - it's probably a better approach. It will be quicker (not a major
problem in this application) and the screen won't jump around all over the
place. Plus then you won't have to somehow relocate the cursor back to where
you started. (I reckon Shasur only made such extensive use of the Selection
object because you were...)
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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