Function EmbraceIn (some [pair of] character[s])

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15656
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Function EmbraceIn (some [pair of] character[s])

Post by ChrisGreaves »

If I've done it right, these little bits of code provide a starter model for anyone who wants to emulate, in MSWord, an effect similar to using the B, U, I and URL buttons in composing a post here in Eileen's lounge.

I got tired of scooting around a document putting things in double-quotes long after I'd typed in the text.
I can think of several enhancements, amongst them an option to trim the selection of any leading or trailing spaces.
In the meantime, drop this code into your Normal.dot, select a word or phrase, and run a macro.

Code: Select all

Function EmbraceIn(strText As String)
    ''' Chris Greaves 28 Feb 2014
    ''' This function does NOT test for an appropriate selection (length, context etc.)
    ''' This function aims to place a single character before and after a selected portion of text.
    ''' I generally assign the macro EmbraceInSmartQuotes to the shortcut key Ctrl-Shift-"
    Dim rng As Range
    Set rng = Selection.Range
    rng.InsertAfter (Right(strText, 1))
    rng.InsertBefore (Left(strText, 1))
'Sub TESTEmbraceIn()
'    Call EmbraceIn("""")
'End Sub
End Function
Sub EmbraceInStraightQuotes()
    Call EmbraceIn("""")
End Sub
Sub EmbraceInSmartQuotes()
    Call EmbraceIn(ChrW(8220) & ChrW(8221))
End Sub
Sub EmbraceInSquareBrackets()
    Call EmbraceIn("[]")
End Sub
Sub EmbraceInSolidus()
    Call EmbraceIn("|")
End Sub
He who plants a seed, plants life.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Function EmbraceIn (some [pair of] character[s])

Post by Rudi »

Getting lazy in the day?? :evilgrin:
Another addition to the Sub's would be one that adds the quotes/brackets on either side of a sentence. Then you can simply position the flashing cursor on a sentence and the prefix and suffix gets added to wrap the sentence. (That is of course if one is too lazy to CTRL+Click on the sentence).
Mind you, its pretty hard work to triple click on a paragraph too...


TX Chris...They work well.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.