Solved

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

Posted on 2010-11-27
3
437 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
  • 2
3 Comments
 

Author Comment

by:gswitz
Comment Utility
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wpf develop 5 29
.Net Web Site Password specs 2 19
Expando 4 33
Windows Service to Receive TCP Packets 4 30
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now