Consulting

Results 1 to 6 of 6

Thread: Solved: Opening Outlook from Excel and sending to a mailing list

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Solved: Opening Outlook from Excel and sending to a mailing list

    Hi All,
    I'm using the following code from Excel to create an email ("16" replaces a workbook reference). Two questions.
    What do I have to add to open Outlook, making the email visible for final editing before sending?
    I've used the name of a mailing list in .to = "Valuations" which doesn't work. Can this be made to work, or do I just have to add the recipients to the code?
    Regards
    Malcolm
    [VBA]Sub eMailValuation()

    Dim OL As Object
    Dim EmailItem As Object
    Dim Wb As Workbook
    Dim MySub As String
    Dim MyText As String
    Dim MyVal As String
    Dim MySum As String

    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(olMailItem)
    Set Wb = ActiveWorkbook

    MySub = "Kitchen Project - Valuation No. " & "16"
    MyText = "Please find attached our Valuation No. " & "16" & _
    " together with a list of included properties." & vbCr & vbCr & _
    "Regards," & vbCr & vbCr & "Malcolm"
    MyVal = "F:\Valuations\Val" & Format("16", "000") & ".mdi"
    MySum = "F:\Valuations\Summary.mdi"

    Wb.Save
    With EmailItem
    .Subject = MySub
    .Body = MyText
    .To = "Valuations"
    .Importance = olImportanceNormal
    '.Attachments.Add MyVal
    '.Attachments.Add MySum
    .Save
    End With
    Application.ScreenUpdating = True

    Set Wb = Nothing
    Set OL = Nothing
    Set EmailItem = Nothing

    End Sub[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi Malc,
    EmailItem.Display will show the mail item
    I'll have to check about referring to mailing lists tomorrow (Outllok at work, y'see)
    K :-)

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks Killian
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    OK, I've had a test that works for me...
    I think the best approach to adding a Distribution List by name is this. If your name doesn't resolve, we'll have to have a re-think...[VBA]With myMailItem
    .Display
    Set myRecipient = .Recipients.Add("TestDistList")
    myRecipient.Type = olTo
    myRecipient.Resolve
    End With
    [/VBA]
    K :-)

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Killian,
    I had a problem with the Type line so I deleted it (Practical Computing Rule 18)
    The following works fine. Thanks for your help.
    Regards
    Malcolm
    [VBA]
    With EmailItem
    .Subject = MySub
    .Body = MyText
    Set myRecipient = .Recipients.Add("TestDistList")
    myRecipient.Resolve
    .Importance = olImportanceNormal
    '.Attachments.Add MyVal
    '.Attachments.Add MySum
    .Save
    .Display
    End With
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Knowledge Base Approver VBAX Expert brettdj's Avatar
    Joined
    May 2004
    Location
    Melbourne
    Posts
    649
    Location
    Quote Originally Posted by mdmackillop
    I had a problem with the Type line so I deleted it (Practical Computing Rule 18]
    Very droll

Posting Permissions

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