[RESOLVED] Add recipient to VB send mail
I would like to know how to add recipients when using the send mail command.
I have a "SUBMIT" button on a Word document, that invokes VB code to email the form.
The code below works to bring up email message with the word form as the attachment, however the TO: field is blank. I would like the To: field to be automatically filled in with my email address.
Private Sub CommandButton1_Click()
ActiveDocument.SendMail
End Sub
Please help.
Thanks
Krystal
Re: Add recipient to VB send mail
Hi,
I'm not sure you can add a recepient using this code but there is another way of sending your document where you can add a subject and recepients:
vb Code:
Private Sub CommandButton1_Click()
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
.Subject = "New subject goes here"
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route
End Sub
Is this what you need?
Re: Add recipient to VB send mail
Thank you - this is what I was looking for. However when adding this code, I now receive a runtime error of 5892 "Method of 'Has Routing Slip' of object '_Document' failed.
Any ideas on how to fix this?
Re: Add recipient to VB send mail
What program are you running this code in?? e.g Word 2007??
Re: Add recipient to VB send mail
Re: Add recipient to VB send mail
Ar we may have a problem then. I recently read that RouteSlip has been removed from 2007. Thats not good. Try this code any way and if it dosen't work we can try something else:
vb Code:
varName = ActiveDocument.Name
If Documents(varName).HasRoutingSlip = True Then
With ActiveDocument.RoutingSlip
.Subject = "New subject goes here"
.AddRecipient "user@user"
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route
End If
Re: Add recipient to VB send mail
I made the modifications, but still receive the same run-time error.
Re: Add recipient to VB send mail
Right, try this code then, we are using outlook application as an object:
vb Code:
Dim olApp As Object
Dim olMsg As Object
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
With olMsg
.To = "email add"
.Subject = "subject"
.Body = "body"
.Attachments.Add Me.Path + "\" + Me.Name
.Send
End With
Set olMsg = Nothing
Set olApp = Nothing
Re: Add recipient to VB send mail
Awesome!!! That worked!!
However, when opening the form that was emailed, it did not save the information inputted into the form - it is just the blank form. Is there a way to have what the user inputted emailed?
Thanks for all of your help!
Re: Add recipient to VB send mail
Thats fine, glad we could get that sorted!
Not sure i understand the next part though.
Do you mean you want the body of the email to me what is written on the page?!? As well as the document being attached. This is possible, if that is what you mean?
Re: Add recipient to VB send mail
Sorry - let me go step by step to help explain myself better.
A user completes the form - and clicks on the SUBMIT button.
I have the macro you provided to me assigned to the SUBMIT button.
The form is then emailed to me as expected (as an attachment).
However, when I open the emailed attachment, it is blank, and does not contain the information that the user completed on the form.
Does that help make sense of it all?
Re: Add recipient to VB send mail
Yes, unless im being stupid, you want to send the attachment to yourself and you want the information from the form to also be the body of the email?!?!
Re: Add recipient to VB send mail
Actually I just wanted the completed information in the form to be the attachment instead of the blank form.
I think I figured out a work around though - to just do a save first.
Thanks for all of your help!
Re: [RESOLVED] Add recipient to VB send mail
Oh right i see, yer just saving it so the attatchment updates.
This line of code could probably be better:
vb Code:
.Attachments.Add Me.Path + "\" + Me.Name
But if it aint broke don't fix it.
Goood luck
Re: [RESOLVED] Add recipient to VB send mail
I am also trying to set up a user-completed form that would be emailed back to me, and am not receiving the data back, just the blank form. I am using the code provided above:
Dim olApp As Object
Dim olMsg As Object
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
With olMsg .To = "email add"
.Subject = "subject"
.Body = "body"
.Attachments.Add Me.Path + "\" + Me.Name
.Send
End With
Set olMsg = Nothing
Set olApp = Nothing
Any suggestions?
Re: [RESOLVED] Add recipient to VB send mail
Quote:
Originally Posted by
gmaradiaga
I am also trying to set up a user-completed form that would be emailed back to me, and am not receiving the data back, just the blank form. I am using the code provided above:
Dim olApp As Object
Dim olMsg As Object
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
With olMsg .To = "email add"
.Subject = "subject"
.Body = "body"
.Attachments.Add Me.Path + "\" + Me.Name
.Send
End With
Set olMsg = Nothing
Set olApp = Nothing
Any suggestions?
Hi,
I'm not sure if this will give some advice or not?
http://www.vbforums.com/showthread.php?t=557488
Re: [RESOLVED] Add recipient to VB send mail
Thank you all for this information. You have helped me sooooo much.