• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

I need to change the value of a List Control in a Word Document using C#

using Word = Microsoft.Office.Interop.Word;
            var wordApp = new Word.Application();
            wordApp.Visible = true;
            Word.Documents docs = wordApp.Documents;
            Word.Document doc = docs.Open(@"c:\temp\test3.docx", Type.Missing, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            Word.Range range = doc.Range(0, 0);

            foreach (Word.ContentControl word_cc in doc.ContentControls)
            {
                MessageBox.Show(word_cc.Range.Text + "\r\n" + word_cc.Title + "\r\n" + word_cc.Tag);
                //word_cc.Range. = "Female";
                if (word_cc.Title=="Gender")
                {
                    string s1=word_cc.DropdownListEntries.ToString();
                    MessageBox.Show(s1);
                }

            }

            doc.Close(Type.Missing, Type.Missing, Type.Missing);
            wordApp.Quit(Type.Missing, Type.Missing, Type.Missing);




test2.docx
0
gswitz
Asked:
gswitz
  • 2
1 Solution
 
GrahamSkanCommented:
You need to use the Select method of ContentControlListEntry object.

Here is some VBA macro code.
Dim cc As ContentControl
    Dim ccle As ContentControlListEntry
    
    For Each cc In ActiveDocument.ContentControls
        If cc.title = "Gender" Then
            For Each ccle In cc.DropdownListEntries
                If ccle.Value = "Female" Then
                    ccle.Select
                    Exit For
                End If
            Next ccle
        End If
        Exit For
    Next cc

Open in new window

0
 
gswitzAuthor Commented:
foreach (Word.ContentControl word_cc in doc.ContentControls)
            {
                if (word_cc.Title=="Gender")
                {
                    foreach(Word.ContentControlListEntry ddle in word_cc.DropdownListEntries)
                    {
                        if (ddle.Value == "Female") ddle.Select() ;
                    }
                }

            }
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now