Results 1 to 31 of 31

Find files in folder where part of file name match Range and attach to Mail.

Threaded View

  1. #1
    Forum Contributor ANDREAAS's Avatar
    Join Date
    05-06-2013
    Location
    Port Elizabeth, South Africa
    MS-Off Ver
    Excel 2007 / 2010
    Posts
    368

    Find files in folder where part of file name match Range and attach to Mail.

    Hi All

    So, if the macro below finds a "Yes" in
    Sheets("Data Input").Range("O:O")
    and the value in that range is "1234" for instance then i want all files in the specified folder where the file name contains 1234 to me attached to the mail.

    So even if the file name is "what a good 1234 day it is", that will be attached to the mail as it contains 1234.

    There are PDF and Excel files in the folder.

    Sub Approval_Mail()
    
        Dim OutApp As Object
        Dim OutMail As Object
        Dim cell As Range
    
        Application.ScreenUpdating = False
        Set OutApp = CreateObject("Outlook.Application")
    
        For Each cell In Worksheets("Data Input").Columns("Q").Cells
            Set OutMail = OutApp.CreateItem(0)
            If cell.Value = "YES" Then
                With OutMail
        .To = Worksheets("Data Input").Range("A55").Value & ";" & Worksheets("Data Input").Range("A54").Value
          .Subject = Cells(cell.Row, "Q").Offset(-1, -1).Value & " " _
            & Cells(cell.Row, "Q").Offset(0, -1).Value & " \ " _
              & Cells(cell.Row, "Q").Offset(-1, -13).Value & " " _
                & Cells(cell.Row, "Q").Offset(0, -13).Value
    .Body = "Good Day" & " " & " Mr. " & Application.UserName & vbNewLine & vbNewLine & _
      "Please see below and attached for your approval." & vbNewLine & "----------------------------------------------------------------------" & vbNewLine _
       & Cells(cell.Row, "Q").Offset(-1, -13).Value & " --> " & Cells(cell.Row, "Q").Offset(0, -13).Value _
        & vbNewLine & vbNewLine & Cells(cell.Row, "Q").Offset(-1, -12).Value & " --> " & Cells(cell.Row, "Q").Offset(0, -12).Value _
         & vbNewLine & vbNewLine & Cells(cell.Row, "Q").Offset(-1, -11).Value & " --> " & Cells(cell.Row, "Q").Offset(0, -11).Value _
          & vbNewLine & vbNewLine & Cells(cell.Row, "Q").Offset(-1, -10).Value & " --> " & Cells(cell.Row, "Q").Offset(0, -10).Value _
          & vbNewLine & vbNewLine & Cells(cell.Row, "Q").Offset(-1, -9).Value & " --> " & Cells(cell.Row, "Q").Offset(0, -9).Value _
        & vbNewLine & vbNewLine & Cells(cell.Row, "Q").Offset(-1, -8).Value & " --> " & Cells(cell.Row, "Q").Offset(0, -8).Value _
       & vbNewLine & vbNewLine & Cells(cell.Row, "Q").Offset(-1, -7).Value & " --> " & Cells(cell.Row, "Q").Offset(0, -7).Value _
     & vbNewLine & vbNewLine & Cells(cell.Row, "Q").Offset(-1, -2).Value & " --> " & Cells(cell.Row, "Q").Offset(0, -2).Value _
    & vbNewLine & "----------------------------------------------------------------------" & vbNewLine & "Thank You."
                    .display
    
                End With
    
                Set OutMail = Nothing
            End If
        Next cell
    
        Set OutApp = Nothing
        Application.ScreenUpdating = True
    
    End Sub
    Thanks in advance for any help.
    Last edited by ANDREAAS; 06-12-2020 at 03:41 PM.
    A great big thank you to all the experts on the forum that are always so friendly and helpful.

    You guys Rock!!!!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Save a copy from attacment to a specific folder when attach a xlsx in mail
    By dodde in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-07-2020, 07:25 AM
  2. [SOLVED] Macro to attach all files in a folder
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-27-2019, 09:01 AM
  3. [SOLVED] Loop Through Folder, Create Emails with Sub Folder Names in Subject, Attach files in sub
    By Rschwar23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2015, 10:06 AM
  4. Replies: 4
    Last Post: 10-17-2014, 09:31 AM
  5. Attach files to E-mail based on partial filename
    By MUCa346 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2014, 11:24 AM
  6. Open up a Lotus Notes Database (not mail) create a new post and attach files VBA Excel
    By exceliscool in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2014, 03:25 PM
  7. [SOLVED] attach file from folder on c:\ to outlook mail and send
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-24-2013, 11:33 AM

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.6.0 RC 1