Results 1 to 17 of 17

Thread: [RESOLVED] Add recipient to VB send mail

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    8

    Resolved [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

  2. #2
    Hyperactive Member mrmojorisin's Avatar
    Join Date
    Oct 2007
    Location
    London Town Vocation: Garden Cricket Genuis
    Posts
    439

    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:
    1. Private Sub CommandButton1_Click()
    2. ActiveDocument.HasRoutingSlip = True
    3. With ActiveDocument.RoutingSlip
    4.     .Subject = "New subject goes here"
    5.     .AddRecipient "[email protected]"
    6.     .AddRecipient "[email protected]"
    7.     .Delivery = wdAllAtOnce
    8. End With
    9. ActiveDocument.Route
    10. End Sub

    Is this what you need?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    8

    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?

  4. #4
    Hyperactive Member mrmojorisin's Avatar
    Join Date
    Oct 2007
    Location
    London Town Vocation: Garden Cricket Genuis
    Posts
    439

    Re: Add recipient to VB send mail

    What program are you running this code in?? e.g Word 2007??

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    8

    Re: Add recipient to VB send mail

    Yes, Word 2007

  6. #6
    Hyperactive Member mrmojorisin's Avatar
    Join Date
    Oct 2007
    Location
    London Town Vocation: Garden Cricket Genuis
    Posts
    439

    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:
    1. varName = ActiveDocument.Name
    2.  
    3. If Documents(varName).HasRoutingSlip = True Then
    4.     With ActiveDocument.RoutingSlip
    5.         .Subject = "New subject goes here"
    6.         .AddRecipient "user@user"
    7.         .Delivery = wdAllAtOnce
    8.     End With
    9. ActiveDocument.Route
    10. End If

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    8

    Re: Add recipient to VB send mail

    I made the modifications, but still receive the same run-time error.

  8. #8
    Hyperactive Member mrmojorisin's Avatar
    Join Date
    Oct 2007
    Location
    London Town Vocation: Garden Cricket Genuis
    Posts
    439

    Re: Add recipient to VB send mail

    Right, try this code then, we are using outlook application as an object:

    vb Code:
    1. Dim olApp As Object
    2. Dim olMsg As Object
    3.  
    4. Set olApp = CreateObject("Outlook.Application")
    5. Set olMsg = olApp.CreateItem(0)
    6. With olMsg
    7.     .To = "email add"
    8.     .Subject = "subject"
    9.     .Body = "body"
    10.     .Attachments.Add Me.Path + "\" + Me.Name
    11.    
    12.     .Send
    13. End With
    14. Set olMsg = Nothing
    15. Set olApp = Nothing

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    8

    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!

  10. #10
    Hyperactive Member mrmojorisin's Avatar
    Join Date
    Oct 2007
    Location
    London Town Vocation: Garden Cricket Genuis
    Posts
    439

    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?

  11. #11

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    8

    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?

  12. #12
    Hyperactive Member mrmojorisin's Avatar
    Join Date
    Oct 2007
    Location
    London Town Vocation: Garden Cricket Genuis
    Posts
    439

    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?!?!

  13. #13

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    8

    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!

  14. #14
    Hyperactive Member mrmojorisin's Avatar
    Join Date
    Oct 2007
    Location
    London Town Vocation: Garden Cricket Genuis
    Posts
    439

    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:
    1. .Attachments.Add Me.Path + "\" + Me.Name
    But if it aint broke don't fix it.


    Goood luck

  15. #15
    New Member
    Join Date
    Jul 2009
    Posts
    1

    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?

  16. #16
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] Add recipient to VB send mail

    Quote Originally Posted by gmaradiaga View Post
    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

  17. #17
    New Member
    Join Date
    Mar 2011
    Posts
    1

    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
  •  



Click Here to Expand Forum to Full Width