Finding the end of the line - where there is a hard carriage retur

D

dhstein

I want to bold the first 3 words in the line then cut them and move to the
end. But I want the end of the line (meaning the next hard CR not the end of
the line where it wraps to the next line) Here's my code and any help is
appreciated:


Sub OneLine()
'
' OneLine Macro
'
'

Selection.MoveRight Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.Cut
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=" - "
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveDown Unit:=wdParagraph, Count:=2
End Sub
 
D

Doug Robbins - Word MVP

Use:

Dim myrange As Range, mywords As Range
Set myrange = Selection.Paragraphs(1).Range
Set mywords = myrange.Duplicate
mywords.End = mywords.Words(3).End
mywords.Font.Bold = True
mywords.Cut
myrange.End = myrange.End - 1
myrange.Collapse wdCollapseEnd
myrange.Paste


--
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, originally posted via msnews.microsoft.com
 
P

Pesach Shelnitz

Hi,

The following macro is your macro with the simplest changes that would
achieve what I think you want it to do.

Sub OneLine()
'
' OneLine Macro
'
'

Selection.MoveRight Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.Font.Bold = True
Selection.Cut
Selection.MoveDown Unit:=wdParagraph
Selection.MoveLeft Unit:=wdCharacter
Selection.TypeText Text:=" - "
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveDown Unit:=wdParagraph, Count:=1
End Sub
 

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