Lounge Formatting via MSWord

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

Lounge Formatting via MSWord

Post by ChrisGreaves »

Forum???

If you use Character Styles, and in particular if you maintain three styles “csB”, “csI” and “csStrikeThrough”, you may find these three macros handy. And yes, they could be streamlined to make use of a slave function.

I spend 95% or more of my time off-line, and prepare texts offline for posting.

With these macros I can do the lounge editing off-line (the {b} and {/b} switches) and see the effect on my text.

I know too that I could make the {b} and {/b} switches hidden so that they wouldn’t clutter my view, but then I’d always be wondering whether I’d used these new-fangled macros or my Shift-Ctrl-B combinations to make the text appear bold.

I could too augment these with LoungeHide and LoungeCode. All the more reason for a slave function ...

Cheers
Chris

Code: Select all

Sub LoungeItalics()
    Dim rng As Range
    Set rng = Selection.Range
    Dim lngStart As Long
    lngStart = rng.Start
    Dim strText As String
    strText = "[i]" & Selection.Range.Text & "[/i]"
    Selection.TypeText Text:=strText
    rng.End = Selection.End
    rng.Select
    rng.Style = ActiveDocument.Styles("csI")
End Sub
Sub LoungeBold()
    Dim rng As Range
    Set rng = Selection.Range
    Dim lngStart As Long
    lngStart = rng.Start
    Dim strText As String
    strText = "[b]" & Selection.Range.Text & "[/b]"
    Selection.TypeText Text:=strText
    rng.End = Selection.End
    rng.Select
    rng.Style = ActiveDocument.Styles("csB")
End Sub
Sub LoungeStrikethrough()
    Dim rng As Range
    Set rng = Selection.Range
    Dim lngStart As Long
    lngStart = rng.Start
    Dim strText As String
    strText = "[s]" & Selection.Range.Text & "[/s]"
    Selection.TypeText Text:=strText
    rng.End = Selection.End
    rng.Select
    rng.Style = ActiveDocument.Styles("csStrikeThrough")
End Sub
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
HansV
Administrator
Posts: 78411
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Lounge Formatting via MSWord

Post by HansV »

Hi Chris,

What is the purpose of the variable lngStart? You set its value to rng.Start, but don't use it after that...
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78411
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Lounge Formatting via MSWord

Post by HansV »

You could simplify (for example) LoungeItalics to

Code: Select all

Sub LoungeItalics()
    With Selection
        .InsertBefore "[i]"
        .InsertAfter "[/i]"
        .Style = ActiveDocument.Styles("csI")
    End With
End Sub
Best wishes,
Hans

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

Re: Lounge Formatting via MSWord

Post by ChrisGreaves »

HansV wrote:What is the purpose of the variable lngStart? You set its value to rng.Start, but don't use it after that...
Thanks Hans.
Vestigal Basic for Applications is my best guess (grin!)
Chris
There's nothing heavier than an empty water bottle

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

Re: Lounge Formatting via MSWord

Post by ChrisGreaves »

HansV wrote:You could simplify (for example) LoungeItalics to ...
Quite so!
Indeed I might borrow your code and make it my Slave Procedure.
Two parameters should do the trick.
:thankyou:
Chris
There's nothing heavier than an empty water bottle