word form filling and email as attachment

I am a simple person who likes to do things a simple way. I assumed it would be a trivial exercise to create a form in Word for endusers to fill in simple data, and then include a command button to send the completed form to a specific email address as an attachment. I do not wish to set up a web server, or an exchange server, or a sharepoint server (or any complicated stuff) to achieve this. We have users with Office 2000, 2003, 2007 and probably 2010 fairly soon, and from what I have read so far, various useful features keep getting disabled as the versions get more recent. Will I be forced to use Open Document Format to get anything useful done?

 

August 24th, 2010 8:57pm

Hi,

You can add a command button in the page of document, for example this command button called "Submit".

Then try this VB script:

Private Sub CommandButton1_Click()
    Options.SendMailAttach = True
    ActiveDocument.SendMail
End Sub Hope it helps.
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2010 7:32am

Yes, I guess that is a solution, but I was hoping to be able to set the recipient and the subject inside the code & not have the email client popping up. Also, is this assuming that every user will have Outlook installed, or does it find whatever default email client is installed?
August 26th, 2010 4:20am

I believe the following code snippet will assist you in sending the form to a user silently with a predefined Recipient and Subject. 

 

Please create a command button with the following code under the Click event.

 

Private Sub CommandButton1_Click()    

Dim OL              As Object

Dim EmailItem       As Object

Dim Doc             As Document

 

Application.ScreenUpdating = False

Set OL = CreateObject("Outlook.Application")

Set EmailItem = OL.CreateItem(olMailItem)

Set Doc = ActiveDocument

Doc.Save

 

With EmailItem

    .Subject = "Insert Subject Here"

    .Body = "Insert message here" & vbCrLf & _

    "Body Line 2" & vbCrLf & _

    "Body Line 3"

    .To = "emailaddress@companyname.com"

    .Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow

    .Attachments.Add Doc.FullName

    .Send

End With

 

Application.ScreenUpdating = True

 

Set Doc = Nothing

Set OL = Nothing

Set EmailItem = Nothing

    

End Sub

Free Windows Admin Tool Kit Click here and download it now
August 31st, 2010 4:37pm

Hey Jennifer,

Thank you this is almost exactly what I've been looking for, for two days now. Everything works as planned, but I have a question. Do you know if you can preset a recipient? I'd like to have the command pre-fill the email to field.

Thank you so much!

Tim

March 8th, 2012 8:30pm

tgelhardt,

In the code above, this line - 
    .To = "emailaddress@companyname.com"

is where you preset the recipient. Change this to fit your needs.

Hope this helps,

David

Free Windows Admin Tool Kit Click here and download it now
March 9th, 2012 4:01pm

Just wanted to say thank you, thank you, thank you so much. 

I have been searching for over two days to find a code that submits a user form via a submit button in Word 2010 as an attachment to an email and the above works perfect.

Thank you once again.

April 25th, 2012 10:36am

Hi,

I was working on the same thing and your code really really helps! But after copying this code, when the user fill up the form, and click the button, the form will send atomatically to the address in the code. I would like to know if there is any other code that when the user click the button, the email page will appear for the user to type in the message first before sending the form automatically to that address. I want that in case my user needs to edit the message in the mail before sending that back.

Thanks in advance!


  • Edited by mO-Ni-rOtH Friday, May 04, 2012 9:31 AM
Free Windows Admin Tool Kit Click here and download it now
May 4th, 2012 9:30am

I'm trying to use this code but, for some reason, the button doesn't do anything when I click on it.

Do I have to do something else to make Word run the code when I click on the button?

May 25th, 2012 6:13pm

Nevermind. I had to allow macros in order for this to work. Awesome code!!!!!!!
Free Windows Admin Tool Kit Click here and download it now
May 25th, 2012 6:33pm

Hi,

I'm having a similar problem. While I can get both of the codes provide above to work individually I was wondering if you ever came across a solution to combine the both of them?

I have a form that users need to fill in and then have it sent to predefined email address as an attachment. I would like to for the users to be able to edit email message before sending.

Thanks :)

May 6th, 2013 5:17am

Hi, thanks for this.

Set EmailItem = OL.CreateItem(olMailItem)

I'm getting a "variable not defined" when steping though this code. I'm not sure where this variable gets established before this line of code. What should I try next. Thanks in advance, B

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2013 3:54pm

I get the error on "olMeailItem", Thanks, B

July 10th, 2013 3:55pm

Hi Adrian,

The code above worked well, only I wonder if it is possible to tweak so that the email address used is one selected from with in the form. I have 10 possible addresses to use, depending on the Committee selected (display name) to the email (value field).

Kind regards

Andrew

Free Windows Admin Tool Kit Click here and download it now
September 16th, 2013 3:36pm

Is it possible to use this method if there isn't a desktop based email client? We use webmail (Outlook 365).
September 2nd, 2015 5:00am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics