none
How do you insert a bullet symbol into a Word document using Visual Studio 2010? RRS feed

  • Question

  • I would just like to be able to insert a bullet into a Word document using Visual Basic. For example:

    "The following requirements must be met:

    • blah, blah
    • blah, blah
    • blah, blah"

    How can I insert a bullet before the "blah, blah" in a Word document using Visual Basic?  Can it be done?

    Thanks in advance,

    Jim


    James Hutchinson

    Sunday, January 31, 2016 1:16 AM

All replies

  • Hi Jim,

    To add bullet to the paragraphs, we could use ListFormat.ApplyListTemplateWithLevel method.

    The recorded macro is:

    Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
            ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
            False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
            wdWord10ListBehavior

    Please refer to this code to achieve that through VB language.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 1, 2016 9:48 AM
    Moderator
  • Hi Jim,

    Yes, it can be done. Check following codes:

    Imports Spire.Doc
    Imports Spire.Doc.Documents
    
    Namespace WordBullets
        Friend Class Program
            Shared Sub Main(ByVal args() As String)
                'Load Document
                Dim doc As New Document()
                doc.LoadFromFile("E:\References.docx")
    
                'Set Bullet Style
                Dim s As Section = doc.Sections(0)
    
                For i As Integer = 1 To s.Paragraphs.Count - 1
                    Dim p As Paragraph = s.Paragraphs(i)
                    p.ListFormat.ApplyBulletStyle()
                    p.ListFormat.CurrentListLevel.NumberPosition = -10
                Next i
    
                'Save and Launch
                doc.SaveToFile("sample.docx", FileFormat.Docx)
                System.Diagnostics.Process.Start("sample.docx")
            End Sub
        End Class
    End Namespace

    In this solution, I used a free .net word library,  and the result is similar with what you described. If you do not mind, you can have a try. Before using the code, do remeber to add the corresponding dll as reference.

    Tuesday, February 2, 2016 8:18 AM
  • Shawn,

    Could you please show me how I would add the dll that you described?  I've never done this.

    Thanks,

    Jim


    James Hutchinson

    Wednesday, February 3, 2016 9:16 PM
  • I was able to create a bullet in a table cell using this line of VB code:

    tbl2.Cell(3, 1).Range.ListFormat.ApplyBulletDefault()

    Does anyone know how I could add different types of bullets using this construct?  The line of code above just creates a basic round bullet in table cell (3, 1).  I would like to be able to create a variety of sub-bullets also.

    Thanks,
    Jim


    James Hutchinson

    Wednesday, February 3, 2016 9:20 PM
  • Hi Jim,

    You could check the methods of ListFormat object.

    I'd suggest asking separate questions in new forum threads. Thus, forum readers may recognize questions and answers easily.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 4, 2016 3:20 AM
    Moderator
  • You really should define paragraph Styles having the various formats you'll need and add them to your document's template. Your code need only then apply those Styles, as & when needed. Indeed, your boilerplate content should likewise be added to the template, formatted with the relevant Styles, so none of it has to be generated each time you need a new document. Using code to apply non-standard formatting to existing Styles makes the resulting documents harder to maintain and more prone to corruption.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, February 5, 2016 5:31 AM
  • Paul,

    I'm afraid that I don't have enough VB experience to implement your suggestion about defining paragraph Styles.  If you can give me a simple example of how to do this and where I need to insert the Styles definitions in my program, I would greatly appreciate it.

    Would these Styles be implemented in a separate VB program and linked to my existing program?

    I think one potential problem with the Styles definitions is that the structure of my tables will change depending on what options are selected by the user.  In other words, the structure of my tables will not necessarily be the same every time.  There could be as many as 20 different table formats, depending on what the user selects.

    Thanks,

    Jim


    James Hutchinson

    Thursday, February 11, 2016 12:45 AM
  • You wouldn't use code to define the Styles. This is a once-off task that can be done manually. Having defined the Styles and added them to the template, they're available for use any time they're needed. They're also much easier to maintain if they exist in the template rather than in code.

    The same principles apply to the content; any 'boilerplate' content should exist in the template, appropriately formatted using Styles, so all you need do create a new document from the template (via the .Documents.Add method) then supplement what's already there with the variable content, which you could insert into pre-defined bookmarks, tables, etc. (using the previously-defined Styles) that already exist in the template and, hence, the document you've just created from it.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, February 11, 2016 1:06 AM
  • Paul,

    If I have 20 different templates, can I link to them from my VB program?

    If so, can you provide an example of how I would do that?

    Thanks,

    Jim


    James Hutchinson

    Thursday, February 11, 2016 3:43 PM
  • As I said in my previous post, you'd do that by referencing the template name when you create the new document. For example, in VBA you might use:

    Dim Doc As Word.Document
    Set Doc = Word.Application.Documents.Add(Template:="Template Fullname")

    where 'Template Fullname' is the name of the template you want to base the document on.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, February 11, 2016 9:14 PM
  • it would be required to have styles specified inside the code instead of use template.  the reason is for the code may use by a colleague that i have no control to set up templates in his computer.  would there be able to have a code to achieve the purpose.  I want to use the checkbox for bullet point.  the checkbox is taken from the first row of the Windings font.  please please help!!

    AlexD


    Kevin Alx

    Monday, October 30, 2017 8:38 PM
  • Tuesday, October 31, 2017 1:00 AM