Search code examples
excelvbams-wordword-contentcontrol

Editing The ContentControl in Word from Excel VBA


I want to edit the plain text content control in my Word application.

I searched but it seems The "plain text content control" in my target Word document does not respond to

objDoc.SelectContentControlsByTag("Name").Item(1).Range.Text

I tried with "ActiveDocument" options but I want it not to work with the active ones.

Code in VBA Excel:

Sub dataToWord()

    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Open("C:\Users\ASUS\Documents\Excell to Word - Copy\WordTesting1.docx")
   
    objWord.Visible = True
    objDoc.SelectContentControlsByTag("Name").Item(1).Range.Text = "I want to type some text here"
  
    objDoc.Save
    objDoc.Close

End Sub

I get:

Run-time error '445':
Object doesn't support this action

It refers to the line

objDoc.SelectContentControlsByTag("Name").Item(1).Range.Text = "I want to type some text here"

Solution

  • I have disabled the WPS app . and it worked fine.. it seems it is in conflict with the microsoft word application..