Results 1 to 8 of 8
  1. #1
    Star Lounger
    Join Date
    Feb 2001
    Location
    Vancouver, BC, Br. Columbia, Canada
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Send mail from Word

    Using VBA, I want to mail the current Word document as an attachment. The following code works, but how can you put in the name of the recipient. It's always the same person and I don't want to create a special Outlook form for this.


    Options.SendMailAttach = True
    ActiveDocument.SendMail

    Any help out there??
    Gwenda

  2. #2
    Star Lounger
    Join Date
    Feb 2001
    Location
    Vancouver, BC, Br. Columbia, Canada
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send mail from Word

    The answer was in "Word 2000 VBA Programmer's Reference" by Duncan Mackenzie. Word's sendmail object does not allow you to set any properties, like a recipient's email address, body text, etc. You have to add the Outlook library to your project References (TOOOLS, References). Then you have access to Outlook's own beautiful object model. The actual code follows:

    Sub MailProposal(sRecipient As String, strFullFileName As String)

    Dim objOutlook As Outlook.Application
    Dim nsMAPI As Outlook.NameSpace
    Dim objOutbox As Outlook.MAPIFolder
    Dim objNewMessage As Outlook.MailItem

    Set objOutlook = New Outlook.Application
    Set nsMAPI = objOutlook.GetNamespace("MAPI")
    Set objOutbox = nsMAPI.GetDefaultFolder(olFolderInbox)
    Set objNewMessage = objOutbox.Items.Add

    With objNewMessage
    .To = sRecipient
    .Subject = "test"
    .Body = ""
    .Attachments.Add strFullFileName .Send
    End With

    Set objOutlook = Nothing
    Set nsMAPI = Nothing
    Set objOutbox = Nothing
    Set objNewMessage = Nothing
    Exit Sub
    End Sub

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send mail from Word

    Sorry we couldn't help you. But thanks for putting up the answer. I've learnt something, and it will be usefule to anybody else who comes along.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    Sandi
    Guest

    Re: Send mail from Word

    Would "routing" the document work for you? You can do this through VBA and set the subject line text and recipient(s).

  5. #5
    Star Lounger
    Join Date
    Feb 2001
    Location
    Vancouver, BC, Br. Columbia, Canada
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send mail from Word

    Thanks Sandi, I would love to know how to program Exchange, but I don't
    G

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send mail from Word

    Gellwood,

    Thanks for posting this code. I found it useful too.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    New Lounger
    Join Date
    Nov 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send mail from Word

    This was code I was looking for to complete a project. I do have one additional question. For the .Attachments.Add line, you are getting a Filename from the user (strFullFileName) but how can I just attach the current document that's on screen?

    Any help would be appreciated. Thank you.

  8. #8
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Send mail from Word

    You need to give that variable a value somewhere in the macro before it is called
    strFullFileName = ActiveDocument.FullName

    You may also need to make sure the document is saved before attaching it. Otherwise you will get the saved version which may not be the same as the loaded (screen) version. The code for that is
    ActiveDocument.Save
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •