View Single Post
 
Old 02-08-2024, 04:31 AM
ppereira ppereira is offline Windows 10 Office 2021
Novice
 
Join Date: Feb 2024
Posts: 2
ppereira is on a distinguished road
Default Change text in a Word content control with VBA in Excel

Hi,
I have data in a Excel sheet and a macro.
When i run the macro i want to populate with some data, in this excel, to a Word document.
I bookmark the content control in Word.
My approach:

Code:
Sub ReplaceText()
Dim wApp As Word.Application
Dim wdoc As Word.document

Set wApp = CreateObject("Word.Application")

wApp.Visible = True

Set wdoc = wApp.Documents.Open(ActiveWorkbook.Path & "\teste.docx")

Dim control As ContentControl
Set control = ActiveDocument.SelectContentControlsByTitle("my_name_control").Item(1).Range.Text = newtext


End Sub
I read some post in the forum but cant put this working.
Could some one give a hint?
Thanks
Reply With Quote