LauraBlair
New Member
- Joined
- Feb 9, 2021
- Messages
- 13
- Office Version
- 365
- Platform
- Windows
Hi all, I am fairly new to VBA and i have found a code which i have altered slightly to populate text content controls in word.
I have named the cells in excel, and i have given all content controls in the work doc a title, but still cant get it to work. The code runs, but cant seem to access the content controls so the word doc opens but the content controls remain blank.
Any assistance would be greatly appreciated, what am i missing?
Thank you
I have named the cells in excel, and i have given all content controls in the work doc a title, but still cant get it to work. The code runs, but cant seem to access the content controls so the word doc opens but the content controls remain blank.
Any assistance would be greatly appreciated, what am i missing?
Thank you
VBA Code:
Sub Exec_Summary2()
'
Dim objWord As Object
UserName = Environ$("username")
Dim oCC As ContentControl
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Activate
objWord.Documents.Open ("https://XXXX-my.sharepoint.com/personal/" & UserName & "_XXXX/Documents/_MyProfile/Desktop/Business%20Executive%20Summary%20MASTER.docx?web=1")
For Each oCC In ActiveDocument.ContentControls
Select Case oCC.Title
Case "CASENAME" 'This is the Title being referenced for CC in Word
oCC.Range.Text = CAseName 'This is the named cell being referenced in excel
Case "title of control 2"
oCC.Range.Text = whatever
Case "title of control 3"
oCC.Range.Text = whatever
'etc
End Select
Next oCC
End Sub