PDA

View Full Version : Make Submit button Word 2003 send attachment to e-mail



thndrbd2
05-22-2008, 08:14 AM
I am trying to get a command button in Word 2003 to send the document (once the users fills it out) to my e-mail and populate the subject tine.

I have managed to get the button to open e-mail with address and subject provided but not the attachment. I have tried using VB and entering the following code:


Option Explicit

Sub Macro1()
'Display subject in Email

ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
.Subject = "AdHoc Request"
.AddRecipient "donna.mcleod@vdh.virginia.gov"
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route
End Sub

Sub DisplayAttachDocumentInEmail()
'Display activedocument as attachment in Email item to send it

With Application
.Options.SendMailAttach = True
.ActiveDocument.SendMail
End With
End Sub

But it will only execute the second sub and I have to open VB to get it to do it. I want a button that the user need only click and it attaches the document, fills in my e-mail and subject line and allows the user to add any additional information they want in the body of the e-mail.

lucas
05-22-2008, 08:32 AM
Hi Thndrbd2,
If you select your code when posting and hit the vba button it will be formatted as I have done to your code....easier to read.

I use the following to accomplish your task and it has a lot of configuration that I believe will help with your task:
Option Explicit
Sub eMailActiveDocument()
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 & _
"Line 2" & vbCrLf & _
"Line 3"
.To = "User@Domain.Com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Display
' .Send
End With

Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub

If you want to set a menu item instead of a button you might check this out....it is easy and portable. Click Here (http://slucas.virtualave.net/Wink/CustomMenuItem.htm).

thndrbd2
05-22-2008, 10:35 AM
I figured out some of the error code received was due to hyperlinks in the document I have since removed ... now when I run on the line below I receive an error stating "Combile error Variable not defined"

Set EmailItem = OL.CreateItem(olMailItem)

lucas
05-22-2008, 10:47 AM
Are you using outlook? With the code I posted you will have to set a reference to the msOutlook 11.0 object library. In tools references.

thndrbd2
05-22-2008, 11:08 AM
Yes, I am using Outlook Express ... and I am sorry to seem so inept ... but I se not reference in tool sinthe word doc or inmy outlook tools ...

fumei
05-22-2008, 11:13 AM
Steve: "Are you using outlook? "

thndrbd2: "Yes, I am using Outlook Express "

thndrbd2, your answer should have been "no". You are using Outlook Express. That is NOT Outlook.

lucas
05-22-2008, 07:09 PM
Yes, I am using Outlook Express ... and I am sorry to seem so inept ... but I se not reference in tool sinthe word doc or inmy outlook tools ...

Look in the Word VBE where you post your code. Look for the tools menu item....then select references and look for it there.....don't get frustrated it is there. I don't know if it will work with outlook express or not.....let us know.

thndrbd2
05-23-2008, 03:58 AM
I found the setting and no it did not help .. I did not realize Outlook Express and Outlook are not the same thing .. so am I at a stand still? Can I not make this application work because I have Outlook Express?

fumei
05-23-2008, 03:01 PM
That is correct.

" I did not realize Outlook Express and Outlook are not the same thing"

If they were the same thing, why would one be called Outlook Express?

Look at the code.

Set OL = CreateObject("Outlook.Application")



Does it say OutlookExpress.Application? No, it says Outlook.Application. And yes, if you have a reference, it will indeed make an instance of....Outlook.

Not Outlook Express.

hitchcock
03-05-2009, 02:44 PM
Great piece of code but i was wondering if there is a way to make the user not have to select the yes button to allow the sending in outlook. i receive this:

hxxp://www .contextmagic.com/images/microsoft_outlook_prompt2.gif

Basically I want to select yes so the user doesn't have to.

Sorry for the noobish question but thanks for everything already.

fumei
03-06-2009, 01:48 PM
Do a google search on this. There are some software packages that simulate a Yes click. Which of course essentially bypasses the whole security point.

hitchcock
03-06-2009, 02:19 PM
Do a google search on this. There are some software packages that simulate a Yes click. Which of course essentially bypasses the whole security point.

yeah trying to avoid paying for it. besides the form that this code is attached to is going out to hundreds of people. dont want to pay licenses on that may people.

the problem that i have found is that the code doesnt go past the .Send until the box has been answered. so it kills the whole sendkeys commands.

lucas
03-06-2009, 02:26 PM
Don't give up hope. I think this thread addresses your problem and if I remember correctly it finds a solution.....may be wrong.
http://www.vbaexpress.com/forum/showthread.php?t=7847
sendkeys shouldn't be required.


Edit: the board went haywire but I think everything is back to where it should be.......

lucas
03-06-2009, 02:27 PM
Here is an article that addresses the issue also that might help:
http://www.vbaexpress.com/forum/showthread.php?t=16364