Discussion:
Drop down field in Word
(too old to reply)
Shankar
2005-03-27 09:50:06 UTC
Permalink
Hi,
Can i push the items in drop down dynamically in word 2003 document using
.NET. There aren't any code samples available. I tried to record the macro
and convert in C#/VB code but does not seem to work.

Can somebody help in this.

Thanking in advance.
Shankar
Cindy M -WordMVP-
2005-03-28 15:45:21 UTC
Permalink
Hi Shankar,
Post by Shankar
Can i push the items in drop down dynamically in word 2003 document using
..NET. There aren't any code samples available. I tried to record the macro
and convert in C#/VB code but does not seem to work.
Could you show us the macro so that we at least have an idea about which kind
of dropdown you're trying to work with?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Shankar
2005-03-28 20:37:26 UTC
Permalink
Hi Cindy,
Here is the macro I recorded. I need the equivalent C# code for this
action.

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/28/2005 by Shankar Kumar
'
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormDropDown
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = "Dropdown1"
.EntryMacro = ""
.ExitMacro = ""
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
End With
Selection.FormFields("Dropdown1").DropDown.ListEntries.Clear
Selection.FormFields("Dropdown1").DropDown.ListEntries.Add Name:="Item
1"
Selection.FormFields("Dropdown1").DropDown.ListEntries.Add Name:="Item
2"
Selection.FormFields("Dropdown1").DropDown.ListEntries.Add Name:="Item
3"
End Sub

Thx, Shankar
Post by Cindy M -WordMVP-
Hi Shankar,
Post by Shankar
Can i push the items in drop down dynamically in word 2003 document using
..NET. There aren't any code samples available. I tried to record the macro
and convert in C#/VB code but does not seem to work.
Could you show us the macro so that we at least have an idea about which kind
of dropdown you're trying to work with?
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Cindy M -WordMVP-
2005-03-30 10:07:14 UTC
Permalink
Hi Shankar,
Post by Shankar
Here is the macro I recorded. I need the equivalent C# code for this
action.
{
wd.Document doc = wdApp.ActiveDocument;
//ensuring we insert the field at the end of the document
wd.Range rng = doc.Content;
rng.Collapse(ref objCollapseEnd);
wd.FormField ffld = doc.FormFields.Add(rng,
wd.WdFieldType.wdFieldFormDropDown);
ffld.DropDown.ListEntries.Clear();
object objIndex1 = (object) 1;
ffld.DropDown.ListEntries.Add("Three", ref objIndex1);
ffld.DropDown.ListEntries.Add("Two", ref objIndex1);
ffld.DropDown.ListEntries.Add("One", ref objIndex1);
}

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)

Loading...