none
Create and Attach Word document from Outlook 2007 form RRS feed

  • Question

  • I've got a custom email form - when the user hits the "Confirm" button I'd like it to do the following:

    1. Create a Word document using some of the values on the form (ideally via mail merge into an existing template). e.g. a standard form that the recipient will be print, take with them and get signed.

    2. Attach the newly created document to the form

    3. Email the form to the specified resource(s)

    So far I've got the email working, but not been able to get an Word automation working from within Outlook.

    I've tried searching but not stumbled across any code to help, so would appreciate it if anyone could let me know if this is possible and maybe point me at some sample code to get started from.

    Tuesday, June 18, 2013 9:58 AM

Answers

  • This is how you create a new Word doc, assuming you have a reference to the Word Object Model set:

    Sub NewSampleDoc()
        Dim docNew As Word.Document
        Dim objApp As Word.Application
        
        Set objApp = New Word.Application
        objApp.Visible = True
        Set docNew = objApp.Documents.Add
        
    
    End Sub

    Then just use MailItem.Attachments.Add to insert the file into the email, and call MailItem.Send.

    FYI, there's plenty of sample code at OutlookCode.com.


    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Tuesday, June 18, 2013 3:48 PM
    Moderator