在Word标题中粘贴Excel中的文本?

时间:2011-04-05 11:19:02

标签: excel excel-vba header ms-word vba

我正在尝试将Belkin添加到我的word文档的标题中。

情况: Excel: A1 = Belkin | Word: header needs to get Belkin

1 个答案:

答案 0 :(得分:3)

这是一个快速的&脏Excel VBA让你前进 - 创建一个新的单词应用程序/ word文档,并将A1的内容粘贴到标题....

Sub CreateWordDocWithHeader()
Dim WApp As Word.Application
Dim WDoc As Word.Document
Dim WRng As Word.Range

    Set WApp = New Word.Application
    WApp.Visible = True
    Set WDoc = WApp.Documents.Add
    Set WRng = WDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range
    WRng = ActiveSheet.[A1]

    Set WRng = Nothing
    Set WDoc = Nothing
    Set WApp = Nothing
End Sub

希望这会有所帮助....祝你好运!