0

我见过这个,但它对我不起作用;我不知道在哪里insertafter更改typetext。我应该在下面进行什么更改以使部分文本变为粗体?

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
4

1 回答 1

0

当你写.Content.Font.Bold = Trueand .Content.Font.Bold = False时,你在粗体和非粗体之间来回切换。 Content此类的最后一个语句是.Content.Font.Bold = False,所以当然没有任何东西最终是粗体的。

这是一种做你想做的事的方法。它写得非常糟糕而且很快,但它应该让你走上正轨。

    .Content.InsertAfter "not bold "
    .Content.InsertAfter "should be bold"
    .Content.InsertAfter " again not bold, followed by newline"
    .Content.InsertParagraphAfter
    .Content.InsertParagraphAfter
    .Content.InsertParagraphAfter
    .Content.InsertAfter "bold again"
    .Content.InsertAfter " and again not bold"
    .Content.InsertParagraphAfter

    .Words(3).Font.Bold = True
    .Words(4).Font.Bold = True
    .Words(5).Font.Bold = True
    .Words(16).Font.Bold = True
    .Words(17).Font.Bold = True
于 2011-06-22T08:41:19.913 回答