简体   繁体   中英

How do I dynamically fill Word Formfields using VBA

I'm new to VBA and I can't find a solution to my problem. I use a Word Form with a dropdown menu. The options in this dropdown menu are names. I want Word to automatically fill in 3 other (regular) Formfields (with contact details) when I chose a name in the dropdown menu. Basically, I want what is explained here (see link), but without use of Microsoft Access:

http://www.techrepublic.com/blog/how-do-i/how-do-i-dynamically-fill-microsoft-word-fields-using-access-data/

After 2 weeks of learning VBA the solution seems so simple. Here's it if anybody needs to accomplish the same. Feel free to use it!

If ActiveDocument.*name of dropdown field* = "contact person 1" Then
    ActiveDocument.FormFields("formfield1").Result = "xxx"
    ActiveDocument.FormFields("formfield2").Result = "xxx"
    ActiveDocument.FormFields("formfield3").Result = "xxx"
ElseIf ActiveDocument.*name of dropdown field* = "contact person 2" Then
    ActiveDocument.FormFields("formfield1").Result = "xxx"
    ActiveDocument.FormFields("formfield2").Result = "xxx"
    ActiveDocument.FormFields("formfield3").Result = "xxx"
ElseIf ActiveDocument.*name of dropdown field* = "contact person 3" Then

...etc

End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM