Link to home
Start Free TrialLog in
Avatar of gswitz
gswitz

asked on

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
Avatar of gswitz
gswitz

ASKER

ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gswitz

ASKER

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() ;
                    }
                }

            }