Excel在A1单元格中为我提供了自定义的文本,然后应将其传递到特定部分(在书签之后)的单词字母。
刚从VBA开始,发现并编辑了能够提供一半解决方案的代码。我遇到的困难是如何将表OutputText的A1单元格中的文本插入书签之后的word文档?
到目前为止,这是我的代码:
Function FnBookMarkInsertAfter()
Dim objWord
Dim objDoc
Dim objRange
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\Users\[...]")
objWord.Visible = True
Set objRange = objDoc.Bookmarks("bookmark_1").Range
objRange.InsertAfter ("Cell A1 from Sheet OutputText")
End Function
谢谢!
答案 0 :(得分:0)
这对您有用吗? (我不能相信该代码):
Sub test()
Dim objWord As Object
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets(1)
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "C:\test.docx" ' change as required
With objWord.ActiveDocument
.Bookmarks("bookmark_1").Range.Text = ws.Range("A1").Value
End With
Set objWord = Nothing
End Sub