Good evening,
I'm trying to get a large set of tagged Content Controls in a .docm word document to update from an excel file.
The Excel File will already be open, but I've been having trouble setting the script to link to the open Excel.
Any help greatly appreciated
Dim cc As ContentControl
For Each cc In ActiveDocument.SelectContentControlsByTag("#uCONM#")
cc.Range.Text = oWB.Sheets("TextElements").Range("B9").Value
Next
For Each cc In ActiveDocument.SelectContentControlsByTag("#lCONM#")
cc.Range.Text = oWB.Sheets("TextElements").Range("B10").Value
Next
The Excel is opened by this
Sub OpenWorkbook()
Dim oXL As excel.Application
Dim oWB As excel.Workbook
Dim oSheet As excel.Worksheet
Dim oRng As excel.Range
Dim ExcelWasNotRunning As Boolean
Dim MasterTemplate As String
'specify the workbook to work on
MasterTemplate = "T:\Trendline\6. Templates\1. Data Extraction Templates\Master_Extraction_Template.xlsm"
'If Excel is running, get a handle on it; otherwise start a new instance of Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
If Err Then
ExcelWasNotRunning = True
Set oXL = New excel.Application
End If
'If you want Excel to be visible, you could add the line: oXL.Visible = True here; but your code will run faster if you don't make it visible
oXL.Visible = True
'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=MasterTemplate)
End Sub