Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2024, 04:31 AM
ppereira ppereira is offline Change text in a Word content control with VBA in Excel Windows 10 Change text in a Word content control with VBA in Excel Office 2021
Novice
Change text in a Word content control with VBA in Excel
 
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
  #2  
Old 02-08-2024, 09:08 AM
Italophile Italophile is online now Change text in a Word content control with VBA in Excel Windows 11 Change text in a Word content control with VBA in Excel Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

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
Reply With Quote
  #3  
Old 02-08-2024, 09:32 AM
ppereira ppereira is offline Change text in a Word content control with VBA in Excel Windows 10 Change text in a Word content control with VBA in Excel Office 2021
Novice
Change text in a Word content control with VBA in Excel
 
Join Date: Feb 2024
Posts: 2
ppereira is on a distinguished road
Default

Thanks. Work Great.

But if i want add a cell value, for example E6, instead of the value "new text"
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change text in a Word content control with VBA in Excel 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
Change text in a Word content control with VBA in Excel 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
Change text in a Word content control with VBA in Excel How to retrieve text from a word content control in VBA jeffaus Word VBA 1 03-14-2013 11:42 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft