Consulting

Results 1 to 3 of 3

Thread: having trouble outputting vba macro into word document

  1. #1
    VBAX Newbie
    Joined
    Jan 2012
    Posts
    1
    Location

    having trouble outputting vba macro into word document

    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

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    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
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    Selection.TypeText Email = ("2@m.org")

    would produce, in the document..

    False

Posting Permissions

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