?
Solved

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

Posted on 2010-11-27
3
Medium Priority
?
450 Views
Last Modified: 2013-12-17
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
Comment
Question by:gswitz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 34222521
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
 

Author Closing Comment

by:gswitz
ID: 34222630
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question