+ Reply to Thread
Results 1 to 2 of 2

Accomplish a Form to Create a Letter?

Hybrid View

matrix1108 Accomplish a Form to Create a... 04-17-2012, 11:52 AM
mrice Re: Accomplish a Form to... 04-17-2012, 12:05 PM
  1. #1
    Registered User
    Join Date
    04-17-2012
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2007
    Posts
    2

    Question Accomplish a Form to Create a Letter?

    Hi guys!

    I hope you guys can help me out here. I want to do a letter generator. Here is the simple version of it:

    The user will be presented with an interface (probably a Word file with a table, or an Excel file) with the following blanks to fill in:
    NAME: ________
    AGE: ___________
    ADDRESS: ________


    The user will then fill up the blanks, then press a button (or a hotkey) then a word file will be created with the following text:

    Hi, <NAME>! I know you are <AGE> years old now. Do you still live in <ADDRESS>?


    (I know my example sounds ridiculous but that's just to give you the idea of what I want to happen. LOL)

    So basically, data from a form will be used in a word file. Is this possible? What should I be looking at, Macros? I'm familiar with doing macros in Excel but not yet in Word.

    Hope someone can help me! Thanks.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Accomplish a Form to Create a Letter?

    From Excel you could try

    Sub CreateWordDocuments()
    Const TargetFolder = "C:\temp\"
    Dim WordApp As Word.Application
    Dim WordDoc As Word.Document
    
    Set WordApp = New Word.Application
    WordApp.Visible = True
    WordApp.Documents.Add
    Set WordDoc = WordApp.ActiveDocument
    WordApp.Selection.TypeText Text:="Hi, " & Range("B1") & "! I know you are " & Range("B2") & " years old now. Do you still live in " & Range("B3") & "?"
    WordApp.Selection.TypeParagraph
    
    Set WordApp = Nothing
    End Sub
    You need to make a reference to the Word object library - Tools - References - Microsoft Word nn.0 Object library
    Martin

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1