Send email form in word 2013 by command buttons in word document. RRS feed

  • Question

  • I need to create a combination of of a drop-down or command buttons to send a document via email.  There 3 managers that all utilize a common form that needs to be submitted via email to a number of distribution lists and email addresses.  

    I can sort of make it work with a single command button, but each manager wants to have a "Submit" button that sends the copy of the document to their own email address, along with the standard distribution groups.

    Ideally I would like to put them into a drop down box, and have a single submit button.  This would have to take the name from the drop down, and input their email address into the email along with the distribution groups.

    Any help would be greatly appreciated!

    Friday, February 28, 2014 2:46 AM

All replies

  • Hello Ericmn78,

    If you develop a VBA macro you may find the How to send an email from Word using VBA article helpful. But if you develop a COM add-in you may find the How to automate Outlook and Word by using Visual C# .NET to create a pre-populated e-mail message that can be edited article useful. It describes all the required code for sending e-mails from Word automatically.

    Friday, February 28, 2014 1:31 PM
  • Thanks for the assistance.

    The first link is what I have been doing, but once you add 3 command buttons, it starts to error.  Invalid procedure.

    • Edited by Ericmn78 Sunday, March 2, 2014 6:11 AM
    Sunday, March 2, 2014 6:11 AM
  • Hello Eric,

    Could you please be more specific? What error do you get? What command buttons are you talking about?

    Sunday, March 2, 2014 12:27 PM
  • I thank you for your assistance: I am not that computer savy, but since I did something like this many years ago with word 2003, I am now expected to figure it out again, and am having much difficulty.  Previously, I was able to make this work with one submit (command) button, but now I am asked to have 3.

    I am getting a "Command button" by the following: Developer > Legacy Tools > Command Button

    I have placed 3 command buttons on my document.  #1 (mgr 1 send) #2 (mgr 2 send) #3 (mgr 3 send).

    I need each button to email the current word document as an attachment and send and email when pressed. Each button will send an email to purchasing and to the manager themselves.

    Private Sub CommandButton1_Click()

    ActiveDocument.HasRoutingSlip = True
    With ActiveDocument.RoutingSlip
         .Subject = "New subject goes here"
         .Delivery = wdAllAtOnce
    End With

    End Sub

    This comes up with an Runtime error '5892':

    The other method I have seen is :

    Private Sub CommandButton1_Click()

    Dim bStarted As Boolean
    Dim oOutlookApp As Outlook.Application
    Dim oItem As Outlook.MailItem

    On Error Resume Next

    If Len(ActiveDocument.Path) = 0 Then
         MsgBox "Document needs to be saved first"
         Exit Sub
    End If

    Set oOutlookApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
         Set oOutlookApp = CreateObject("Outlook.Application")
         bStarted = True
    End If

    Set oItem = oOutlookApp.CreateItem(olMailItem)

    With oItem
         .To =
         .Subject = 
         'Add the document as an attachment, you can use the .displayname property
         'to set the description that's used in the message
        .Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue, _
           DisplayName:="Document as attachment"
    End With

    If bStarted Then
    End If

    Set oItem = Nothing
    Set oOutlookApp = Nothing

    End Sub

    I can not get this string to run at all. It seems to be a problem when I try to attach it to command button.

    Monday, March 3, 2014 2:05 AM
  • Eric,

    Did you try to debug the code? What line of code gives the error? What recipients do you add using the .AddRecipient call?

    Also I have found a similar forum thread which describes exactly the same issue  - Put a button in a Word form to link an email address .

    Monday, March 3, 2014 1:16 PM