我在我的文档上放置了一个纯文本内容控件。
我打开宏并有以下代码
Sub PrefillDocument()
'
' PrefillDocument Macro
'
'
Dim docName As ContentControls
Dim objExcel As Object
Dim FileName As String
FileName = ActiveDocument.Path & "\CountyData.xlsx"
Set objExcel = CreateObject("Excel.Application")
Set exWb = objExcel.Workbooks.Open(FileName)
MsgBox exWb.Sheets("4").Cells(1, 2) // Works
' Having problems trying to get the data from Excel into the content control
Set docName = ActiveDocument.SelectContentControlsByTag("Name") // Get
docName.Item.Title = exWb.Sheets("4").Cells(1, 2)
MsgBox docName.Title
'ActiveDocument.FormFields("Name").Result =
'ThisDocument.m_name.Caption = exWb.Sheets("Member's Data").Cells(2, 1)
exWb.Close
Set exWb = Nothing
End Sub
我被告知不要使用任何旧版控件,因此我被迫使用较新的 ContentControls