Using visual basic in excel to create word document, how do I make some bold text?

Posted by Ernst on Stack Overflow See other posts from Stack Overflow or by Ernst
Published on 2011-06-21T08:17:57Z Indexed on 2011/06/21 8:23 UTC
Read the original article Hit count: 312

Filed under:
|
|
|

I've seen this, but it doesn't work for me, I don't get where to change from insertafter to typetext. What should I change in the following to get part of the text bold as desired?

Sub CreateNewWordDoc()
    Dim wrdDoc As Word.Document
    Dim wrdApp As Word.Application
    Set wrdApp = CreateObject("Word.Application")
    Set wrdDoc = wrdApp.Documents.Add
    With wrdDoc
        .Content.InsertAfter "not bold "
        .Content.Font.Bold = True
        .Content.InsertAfter "should be bold"
        .Content.Font.Bold = False
        .Content.InsertAfter " again not bold, followed by newline"
        .Content.InsertParagraphAfter
        .Content.Font.Bold = True
        .Content.InsertAfter "bold again"
        .Content.Font.Bold = False
        .Content.InsertAfter " and again not bold"
        .Content.InsertParagraphAfter
        .SaveAs ("testword.doc")
        .Close
    End With
    wrdApp.Quit
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
End Sub

Thanks,

Ernst

© Stack Overflow or respective owner

Related posts about vb6

Related posts about excel-2003