Log in

View Full Version : having trouble outputting vba macro into word document



nepix
01-26-2012, 01:32 PM
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

macropod
01-27-2012, 11:51 PM
Cross-posted at: http://www.tek-tips.com/viewthread.cfm?qid=1673236

For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184 (wlmailhtml:{206A3A76-3F8D-4EC1-A542-9FE6C9CDA349}mid://00000086/!x-usc:http://www.excelguru.ca/content.php?184)

fumei
02-03-2012, 08:41 PM
Selection.TypeText Email = ("2@m.org")

would produce, in the document..

False