Using visual basic in excel to create word document, how do I make some bold text?
- by Ernst
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