Consulting

Results 1 to 6 of 6

Thread: Solved: Dont email if no attachment exists

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Solved: Dont email if no attachment exists

    Right now I have the below VBA code to send emails with attachments..Can I incorporate a code in here that says if the attachment ("G:\Katherine Lartigue\Allocations\Fidelity Trades.xls") does not exist, then do not create an email at all?

    Thanks for the help!!

  2. #2
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    you forgot to post your code
    ------------------------------------------------
    Happy Coding my friends

  3. #3
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    ------------------------------------------------
    Happy Coding my friends

  4. #4
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    [VBA]Sub EmailJPMPrivate()
    Dim oOutlook As Object
    Dim oMailItem As Object
    Dim oRecipient As Object
    Dim oNameSpace As Object
    Dim Lastrow As Long
    Dim bodyText As String
    Dim i As Long


    Set oOutlook = CreateObject("Outlook.Application")
    Set oNameSpace = oOutlook.GetNameSpace("MAPI")
    oNameSpace.Logon , , True


    Set oMailItem = oOutlook.CreateItem(0)

    With oMailItem

    Set oRecipient = .Recipients.Add("jpmpb.opm.support4@jpmorgan.com")
    oRecipient.Type = 1

    .Subject = "Avalon Trade Allocations Attached"

    .body = "Please see the attached trade allocations." & vbNewLine & vbNewLine & _
    "Let me know if you need anything else." & vbNewLine & vbNewLine & _
    "Thanks, " & vbNewLine & vbNewLine & _
    "Katherine Lartigue " & vbNewLine & _
    "klartigue@avalonadvisors.com 713-238-2088"

    .Attachments.Add ("G:\Katherine Lartigue\Allocations\JPM Private Trades.xls")
    .Save
    End With

    End Sub[/VBA]

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]Sub EmailJPMPrivate()
    Const FILE_ATTACH As String = _
    "G:\Katherine Lartigue\Allocations\JPM Private Trades.xls"
    Dim oOutlook As Object
    Dim oMailItem As Object
    Dim oRecipient As Object
    Dim oNameSpace As Object
    Dim Lastrow As Long
    Dim bodyText As String
    Dim i As Long


    Set oOutlook = CreateObject("Outlook.Application")
    Set oNameSpace = oOutlook.GetNameSpace("MAPI")
    oNameSpace.Logon , , True


    Set oMailItem = oOutlook.CreateItem(0)

    With oMailItem

    Set oRecipient = .Recipients.Add("jpmpb.opm.support4@jpmorgan.com")
    oRecipient.Type = 1

    .Subject = "Avalon Trade Allocations Attached"

    .body = "Please see the attached trade allocations." & vbNewLine & vbNewLine & _
    "Let me know if you need anything else." & vbNewLine & vbNewLine & _
    "Thanks, " & vbNewLine & vbNewLine & _
    "Katherine Lartigue " & vbNewLine & _
    "klartigue@avalonadvisors.com 713-238-2088"

    If Dir(FILE_ATTACH, vbNormal) <> "" Then

    .Attachments.Add FILE_ATTACH
    .Save
    End If
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    This works great, thanks!!

Posting Permissions

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