Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Park City, Utah
    Thanked 0 Times in 0 Posts

    Simple Drop-Down Dialogue (Word XP VBA)

    I want to create a simple macro which creates a drop-down box listing physicians for a specific client. The user would highlight the name they want and it would be inserted into the document at their cursor location. Is there similar sample code somewhere? (I hate starting from scratch if I don't have to.)

  2. #2
    New Lounger
    Join Date
    Sep 2003
    Thanked 0 Times in 0 Posts

    Re: Simple Drop-Down Dialogue (Word XP VBA)

    Hi there, I am very new to VBA, but i just did something similar myself. Create a form that has a combo box (drop down list) control on it, and an OK button.You need to bookmark the locations in your document that you want the text to be inserted into. Then create code for the OK button that inserts the chosen option from the combo box into the bookmarked location.
    For the OK button code you need something like this:

    Dim rng As Range

    Set rng = ActiveDocument.Bookmarks("boomkark name").Range
    rng.InsertBefore [name opf control]

    To add the items you want to the combo box, add something like this to the control:
    Sub [cntrol name]_DropButtonClick()
    [control name].AddItem "[first choice for list] "
    [control name].AddItem "[second choice for list] "
    [control name].AddItem "[third choice for list] "

    as i said, i am new to this but it worked for me....
    someone out there may have a better way of doing it!
    good luck

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Thanked 7 Times in 7 Posts

    Re: Simple Drop-Down Dialogue (Word XP VBA)

    Another option that you could try is to create a document variable, called for example Physician. This will let you easily use the same information in multiple places in the document. by using the field { DOCVARIABLE "Physician" } . It also has the advantage of allowing you to easily change the name, replacing the existing text in the document with the new text.

    In your UserForm you can change the value of the Document Variable with code like
    ActiveDocument.Variables("Physician").Value = Me.dropdownbox.Value

    You will need to create the document variable - JUST ONCE - with
    ActiveDocument.Variables.Add Name:="Physician", Value:="John Doe"
    You could do this in your form Activate (after checking that it doesn't already exist) or you could do it manually in the VB immediate window.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts