A Word macro for creating a bulleted/numbered list in a post

Getting the most out of Eileen's Lounge!
User avatar
HansV
Administrator
Posts: 69428
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

A Word macro for creating a bulleted/numbered list in a post

Post by HansV »

My esteemed fellow Lounger Rudi has written a macro that converts text in Microsoft Word to the BBCode for a bulleted or numbered list in a post here in Eileen's Lounge.

Code: Select all

Sub MakeLoungeList()
    Dim oPara As Paragraph
    Dim iResp As VbMsgBoxResult
    iResp = MsgBox("Click 'Yes' to convert selected text to a bulleted list. " & vbNewLine & _
        "Click 'No' to convert selected text to a numbered list.", vbYesNoCancel + vbQuestion)
    If iResp = vbCancel Then Exit Sub
    On Error GoTo ErrHandler
    Selection.Expand Unit:=wdParagraph
    For Each oPara In Selection.Paragraphs
        oPara.Range.InsertBefore "[*]"
    Next oPara
    If iResp = vbYes Then
        Selection.InsertBefore "[list]"
    Else
        Selection.InsertBefore "[list=1]"
    End If
    Selection.InsertAfter "[/list]"
    Selection.Copy
    Exit Sub
ErrHandler:
    MsgBox Err.Description, vbExclamation
End Sub
You can copy the macro into a module in the Visual Basic Editor in Word; if you copy it into a module in your default template Normal.dotm, it will be available in all documents.

Usage instructions:

- Select text in Word that you want to post as a list in a post.
- Press Alt+F8 to display the Macros dialog.
- Select MakeLoungeList.
- Click Run.
- Click Yes for a bulleted list, No for a numbered list.

The BBCode for the list will be copied to the clipboard, ready to be pasted into a post.

Thanks for this macro, Rudi!
Regards,
Hans