Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2007

Tip: Looking for answers? Try searching our database.

adjusting selected text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gvm - 16 Jul 2007 12:10 GMT
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
David Sisson - 16 Jul 2007 16:11 GMT
Just move the end of the selection back one character.

> With Selection
   .MoveEnd wdCharacter, -1
Lene Fredborg - 16 Jul 2007 18:36 GMT
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

Signature

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

> 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
[quoted text clipped - 57 lines]
> End With
> End Sub
Doug Robbins - Word MVP - 16 Jul 2007 20:30 GMT
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.

Signature

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

>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
[quoted text clipped - 63 lines]
> End With
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.