vbscript - How to get value of drop down menu in Microsoft Word -


There is a Microsoft Word document with a drop-down menu. I am trying to write a macro which is the value of the drop down value Receives and calculates. How do I get a drop-down price?

After the

First of all, you can get a reference for either the dropdown or the name you want it (Properties box In the bookmark area), or by its number in the sequence added by the fields.

Then you use the result property to show the currently selected value.

I created an empty document with two dropdown list on it (show the tool toolbar, then click on a button to insert that control on the cursor position):

  ColorDropdown Red Green, Blue SizeDropdown Small Medium Large  

So I wrote some test routines:

  Sub ListDropDowns () of the dim doc document As the FormField set document, say F.Name & say in the ActiveDocument doc.FormFields for each F. "=" & Amp; F.Result Next End Sub Sub ShowChosenColor () Set FormField as DimF F = ActiveDocument.FormFields ("ColorDropdown") Say "Color =" & amp; F.Result End Sub Sub (say string) Debug.Print end End Sub  

These are the results of ListDropDowns and ShowChosenColor from the immediate window:

  ColorDropdown = Blue SizeDropdown = Large Color = Blue  

Some more immediate window tests:

  set doc = ActiveDocument? Doc.FormFields (1) .Name ColorDropdown? Doc.FormFields (2) .Name SizeDropdown? Doc.FormFields (2). The result is big sName = doc.FormFields (2) .name? SName size dropdown sSize = doc.FormFields (sName). result? Ssize large  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -