Results 1 to 2 of 2
  1. #1
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form letters using input box (2002)

    I have no experience with word automation, except replacing bookmarks from Access. I have a simple form letter that I would like to have input boxes prompt for various information, and then populate the letter (sometimes in multiple areas) with the data provided. Databasing the info isn't necessary, since it's going to be used once and thrown away. Any guidance would be greatly appreciated.
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What's more, you deserve to be hacked." -Richard Clarke

  2. #2
    5 Star Lounger
    Join Date
    Nov 2004
    Location
    Wilmington, North Carolina, USA
    Posts
    1,196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form letters using input box (2002)

    I figured it out. Here's the code if anyone else wants to use it:

    'note that naming a sub AutoOpen will cause it to automatically execute when the document is opened
    Sub AutoOpen()
    'Check to see if the first bookmark exists. If not, the document has be saved, and you don't want input prompts
    If ActiveDocument.Bookmarks.Exists("bkAddressee") = True Then

    'declare your variables. Each string is a bookmark that was inserted in the word document.
    Dim strAddress1 As String
    Dim strAddress2 As String
    Dim strAddressee As String

    'define your string
    strAddressee = InputBox("Enter addressee title:")

    'select your bookmark
    ActiveDocument.Bookmarks("bkAddressee").Select

    'and then replace it
    Selection.Text = strAddressee

    strAddress1 = InputBox("Enter street address:")
    ActiveDocument.Bookmarks("bkAddress1").Select
    Selection.Text = strAddress1

    strAddress2 = InputBox("Enter city, state, and zip:")
    ActiveDocument.Bookmarks("bkAddress2").Select
    Selection.Text = strAddress2

    Else
    'do nothing
    End If

    End Sub
    ____________________________
    Jeremy
    "If you spend more on coffee than on IT security, then you will be hacked. What's more, you deserve to be hacked." -Richard Clarke

Posting Permissions

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