+ Reply to Thread
Results 1 to 2 of 2

Thread: auto mailing with attachment

  1. #1
    Registered User
    Join Date
    10-15-2011
    Location
    bangalore
    MS-Off Ver
    Excel 2010
    Posts
    45

    auto mailing with attachment

    Hi friends,

    I am very new outlook programming , i am think of automating few of my mails. i ahve folder in D:\Pdf where it contains lots of pdf with names , and fro that names , i have emails ids in excel . when could run a macro in excel can it refer to fiel name and pick the adress from the excel file and send the mail correspondingly , let me know whether this is possible.

    format in excel
    Sl No Producer Name To Mail address Cc Mail address
    1 Ajgallagher Shon_OFallon@ajg.com
    2 Ajg-glendale Mark_Smith-LA@ajg.com

    if you see here producer name "ajgallagher" and my attachment pdf file will also have the same name

    thanks in advance for your ideas

  2. #2
    Registered User
    Join Date
    01-26-2012
    Location
    Slovenia; Kranj
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: auto mailing with attachment

    Hi,

    under producer name you'll need to specifaid whole path, not just file name. As per bottom VBA ...

    | SI No | Producer Name | To | Cc |
    | 1 | D:\Pdf\Ajgallagher.pdf | Shon_OFallon@ajg.com | info@smth.bin |

    Sub Send_PDFs()
        Dim OutApp As Object
        Dim OutMail As Object
        Dim sheet As Worksheet
        Dim cell_to As Range, PDFCell As Range, range As Range
    
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
        Set sheet = Sheets("Sheet1")
    
        Set OutApp = CreateObject("Outlook.Application")
        
        For Each cell_to In sheet.Columns("C").Cells.SpecialCells(xlCellTypeConstants)
    
        'Enter the file names in the B column in each row
        Set range = sheet.Cells(cell_to.Row, 1).Range("B1:B1")
    
        If cell_to.Value Like "?*@?*.?*" And _
            Application.WorksheetFunction.CountA(rng) > 0 Then
            Set OutMail = OutApp.CreateItem(0)
    
            With OutMail
                .To = cell_to.Value
                'Cc = "info@smth.bin"
                .Subject = "Email Subject"
                .body = "I'm sending you ..."
                    
                For Each FileCell In range.SpecialCells(xlCellTypeConstants)
                    If Trim(FileCell) <> "" Then
                        If Dir(FileCell.Value) <> "" Then
                            .Attachments.Add FileCell.Value
                        End If
                    End If
                 Next FileCell
                    
                 '.Send of .Display
                 .Display
            End With
    
            Set OutMail = Nothing
            End If
    
        Next cell_to
    
        Set OutApp = Nothing
    
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        
        End With
    
    End Sub
    ... play with this. You need to add Cc field. i'm using id directly in VBA. Hope this helps.


    Cheers, Marko

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0