Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

having trouble outputting vba macro into word document

Status
Not open for further replies.

nepix

Technical User
Jan 27, 2012
1
US
Hello Guru's!

I have given myself a crash course in vba programming by trying to make a word document with a drop down menu that has several different outputs

for example if you selected "N" in the drop down menu it would populate several different fields throughout the document

I have the drop down menu run the macro below on exit and at this point ive used the { email } field directly in the document and it states "Error bookmark not defined"

How do I output values from the macro into the word document?

thank you in advance for taking the time to point me in the right direction

code below:

Sub stest()
Dim servicearea As String
Dim Email As String
Dim phone As String
Email = "1@m.org"
phone = ("8-- --- ----")

Select Case servicearea
Case "N":
Selection.TypeText Email = ("2@m.org")
Selection.TypeText phone = ("8-- --- ----")

nextcase:
Case "S":
Selection.TypeText Email = ("3@m.org")
Selection.TypeText phone = ("8-- --- ---1")
nextcase2:
Case "K":
Selection.TypeText Email = ("4@m.org")
Selection.TypeText phone = ("8-- --- ---2")
nextcase3:
Case "E":
Selection.TypeText Email = ("5@m.org ")
Selection.TypeText phone = ("8-- --- ---3")
nextcase4:
Case "C":
Selection.TypeText Email = ("6@m.org")
Selection.TypeText phone = ("8-- --- ---4")
nextcase5:
Case "M":
Selection.TypeText Email = ("7@m.org")
Selection.TypeText phone = ("8-- --- ---5")
nextcase6:
Case "O":
Selection.TypeText Email = ("8@m.org")
Selection.TypeText phone = ("8-- --- ---6")

End Select

End Sub
 
Hi nepix,

There is no such thing as an { email } field in Word. There is a HYPERLINK field that can be used for storing clickable email addresses, however. Perhaphs that's what you mean.

In any event, if you're using formfields, your project can be done without vba. Conversely, if you're using a userform, you should investigate the use of custom document properties and DOCPROPERTY fields with vba and how to use & update bookmarks with vba.

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top