#1
|
|||
|
|||
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 Could some one give a hint? Thanks |
#2
|
|||
|
|||
Try:
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") wdoc.SelectContentControlsByTitle("my_name_control").Item(1).Range.Text = "new text" End Sub |
#3
|
|||
|
|||
Thanks. Work Great.
But if i want add a cell value, for example E6, instead of the value "new text" |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Change Value of a Content Control based on the value of another content Control | jsc_msoffice | Word VBA | 2 | 05-21-2021 09:51 PM |
Copy Formatted Text in one Rich Text Content Control to another Rich Text Content Control | Haygordon | Word | 1 | 04-05-2019 05:43 AM |
Change text colour for content control labels? | Toe | Word | 1 | 01-17-2019 08:45 AM |
Is there a way to anchor drop-down content control boxes so entering text doesn't change formatting? | TzarChasm | Word | 7 | 04-14-2016 06:28 PM |
How to retrieve text from a word content control in VBA | jeffaus | Word VBA | 1 | 03-14-2013 11:42 PM |