Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Drop down  field in Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shankar - 27 Mar 2005 10:50 GMT
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- - 28 Mar 2005 16:45 GMT
Hi 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 - 28 Mar 2005 21:37 GMT
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
> Hi Shankar,
>
[quoted text clipped - 14 lines]
> 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- - 30 Mar 2005 11:07 GMT
Hi 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 :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.