28 | 04 | 2017

VisibleVisual.com | Word VB Articles

Add Bullets to Pasted text

The code below can be used to create bullets to existing text or pasted) text within a word document. This can be using when creating document with an external program like Excel. 

The code works by adding a special String that can be detected by the code like ## or @@ or any other string desired. In combination with this string the code needs a level. By setting a level that determines how far down the bullets will be created.

 

Private Sub CommandButton111_Click()

LoopWordCreateBullets 1, "##"
LoopWordCreateBullets 2, "@@"

End Sub

Sub LoopWordCreateBullets(ByVal Level As Integer, ByVal CODE As String)

Dim lstgalleries As Word.ListGalleries

Dim sFindText As String

'Start from the top of the document
With Application
.Selection.HomeKey wdStory
sFindText = CODE
.Selection.Find.Execute sFindText
    Do Until .Selection.Find.Found = False
        .Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=.ListGalleries(wdBulletGallery).ListTemplates(Level), continuepreviouslist:=False, applyto:=wdListApplyToWholeList, defaultlistbehavior:=wdWord9ListBehavior
        
        If i = 1 Then GoTo skipindent
            For i = 1 To Level
                .Selection.Range.ListFormat.ListIndent
            Next i
skipindent:
        .Selection.Range.Delete
        .Selection.MoveRight
        .Selection.Find.Execute
        
        
        
    Loop
End With

End Sub

 

To explain how it works it's possible to use the sample document below (registered users only). Within this document we show how the code works and added sample data.

 

Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2236171
Latest Articles