|
-
Jun 30th, 2008, 01:58 PM
#1
Thread Starter
New Member
[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
-
Jul 1st, 2008, 09:14 AM
#2
Hyperactive Member
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?
-
Jul 1st, 2008, 09:27 AM
#3
Thread Starter
New Member
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?
-
Jul 1st, 2008, 09:41 AM
#4
Hyperactive Member
Re: Add recipient to VB send mail
What program are you running this code in?? e.g Word 2007??
-
Jul 1st, 2008, 09:47 AM
#5
Thread Starter
New Member
Re: Add recipient to VB send mail
-
Jul 1st, 2008, 09:57 AM
#6
Hyperactive Member
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
-
Jul 1st, 2008, 10:26 AM
#7
Thread Starter
New Member
Re: Add recipient to VB send mail
I made the modifications, but still receive the same run-time error.
-
Jul 1st, 2008, 10:45 AM
#8
Hyperactive Member
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
-
Jul 1st, 2008, 10:55 AM
#9
Thread Starter
New Member
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!
-
Jul 1st, 2008, 11:00 AM
#10
Hyperactive Member
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?
-
Jul 1st, 2008, 11:03 AM
#11
Thread Starter
New Member
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?
-
Jul 1st, 2008, 03:11 PM
#12
Hyperactive Member
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?!?!
-
Jul 1st, 2008, 03:19 PM
#13
Thread Starter
New Member
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!
-
Jul 2nd, 2008, 02:20 AM
#14
Hyperactive Member
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
-
Jul 8th, 2009, 01:16 PM
#15
New Member
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?
-
Jul 9th, 2009, 12:25 AM
#16
Re: [RESOLVED] Add recipient to VB send mail
 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
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 9th, 2011, 10:54 AM
#17
New Member
Re: [RESOLVED] Add recipient to VB send mail
Thank you all for this information. You have helped me sooooo much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|