adjusting selected text

G

gvm

I have a macro which reformats selected text and then surrounds it with
quotation marks. To use the macro, I first mark the text to be reformatted by
selecting it with the mouse. Things are not quite perfect because when I mark
the text, Microsoft in its usual helpful way, presumes to include a space
character at the end of the last word. I don't want a superfluous space
character at the end of the block and it is nigh impossible to over-ride the
way Word anticipates (incorrectly) the text I want to mark. Rather than make
the selection process awkward, it is probably better to include a statement
in the macro that deletes the superfluous space character. The macro follows,
TIA ... Greg

Sub Overwrite_linebreaks()
' Keyboard Shortcut Ctrl + 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 = wdColorBlue
.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
.InsertBefore """"
.InsertAfter """" & vbCr
'..InsertAfter Chr(34) & vbCr
.Collapse wdCollapseEnd
End With
End Sub
 
L

Lene Fredborg

If you select Tools > Options > Edit tab and turn off "When selecting,
automatically select entire word", you can select words without the space
being added to the selection.

In VBA, the following will turn off the setting:
Options.AutoWordSelection = false

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
D

Doug Robbins - Word MVP

Dim myrange as Range
Set myrange = Selection.Range
myrange.End = myrange.End - 1
myrange.InsertAfter Chr(34)

Will place a quote mark immediately after the last but one character (or
space) selected by the means that you are doing it. Note however that under
Tools>Options>Edit, you can control the way in which text is selected so
that a whole word (including the space after it) is NOT automatically
selected.

--
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
 

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