Quan
Quan

Reputation: 502

How to replace an existing picture in Picture Content Control in Word 2013+ using Interop C# or VB

I'm using Word 2013. I go to Developer Tab, add a "Picture Content Control" to my document. Set its title as "logo". Then, click on the control and set a default image.

My question is how to replace that default image by any other image using Word Interop (not OpenXML please), language can be C# or VB doesn't matter.

using Microsoft.Office.Interop.Word;

ContentControls controls = d.SelectContentControlsByTitle("logo");
foreach (ContentControl c in controls)
{
    if (c.Type == WdContentControlType.wdContentControlPicture)
    {                        
        // ContentControl of Interop.Word doesn't have Image property
        // Couldn't cast the Microsoft.Office.Tools.Word.PictureContentControl either
    }
}

Upvotes: 2

Views: 1348

Answers (1)

yikekas
yikekas

Reputation: 147

You can replace picture like this,

ContentControls controls = doc.SelectContentControlsByTitle("logo");

foreach (ContentControl contentControl in controls)
{
    var cc = contentControl.Range.InlineShapes.AddPicture("imageLocation");
}

Upvotes: 1

Related Questions