Inserting line break at end of selected text

G

gvm

I have a macro that adjusts a selection of text by replacing line breaks with
spaces and reformatting the format. Now I want to re-insert a line break at
the end of the selection. The macro follows, TIA ... Greg
Sub Overwrite_linebreaks()
' Keyboard Shortcut Ctrl + Alt + F10
If Selection.Type = wdSelectionIP Then Exit Sub
With Selection.Font
.Name = "Times New Roman"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
 
G

Greg Maxey

Greg.

You are not really replacing line breaks. You are destroying paragraphs and
creating a longer sentence. As line break is entered with Shift+Enter and
doesn't create a new paragraph. A line break is found with "^l"

But to do what your macro does now plus what I think you want then try:

Sub Overwrite_linebreaks()
' Keyboard Shortcut Ctrl + Alt + F10
With Selection
If .Type = wdSelectionIP Then Exit Sub
With .Font
.Name = "Times New Roman"
.Size = 12
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^p"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
.InsertAfter vbCr
.Collapse wdCollapseEnd
End With
End Sub
 
G

gvm

Sorry Greg, I should have been clearer in writing my question. At the end of
the selected text, I want to insert a quotation mark followed by the
paragraph break. I've tried a few combinations but obviously am having
trouble combining control characters (I mean vbCr) with text characters (ie
").
 

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