Discussion:
Attach Files to a message - loop through subdirectory
(too old to reply)
Harvey Richardson
2011-05-26 07:28:02 UTC
Permalink
From Outlook, I’m wanting to loop through a subdictory, attach pdf
files to an email ( one pdf file to one email) and send the email to a
fixed email address.

I may want to delete the attachment after it is sent.

I’ve searched the news groups...know how to save attachments to a
subdirectory, but this is the opposite…the files are already in the
subdirectory and I want to send them one at a time!

Any help is appreciated.
Harvey Richardson
2011-05-27 02:13:20 UTC
Permalink
Not sure this is the cleanest code, but I got it to work! Here it is
if anyone needs it:

Sub MyIMAPMacro()

Dim myFileName As String

thefilepath = "s:\scan\To IMAP\"
theemail = "***@me.com.au"

myFileName = Dir("" & thefilepath & "*.*")

Do While myFileName <> ""

Set myOutlook = CreateObject("Outlook.Application")
Set mymail = myOutlook.CreateItem(olMailItem)

myFileName = Dir("" & thefilepath & "*.*")
mymail.Attachments.Add thefilepath & myFileName

mymail.Recipients.Add theemail

lenmyfilename = Len(myFileName)

If Right(myFileName, 4) = ".pdf" Then
thesubject = Left(myFileName, lenmyfilename - 4)
Else
thesubject = myFileName
End If

mymail.Subject = thesubject
mymail.Body = thesubject

mymail.Send
Kill thefilepath & myFileName
myFileName = Dir

Set myOutlook = Nothing
Set mymail = Nothing

Loop

MsgBox "Completed"

End Sub

Loading...