VBA to send files in folder

Joined
Sep 3, 2014
Messages
2
Reaction score
0
Hello All

Hoping for some help

I store all my scanned documents in a folder and want to email them all individually to the same email address with a subject of teh filename without the .pdf extension.

I'm using Outlook 2013 and can get the VBA to send a mail working (From Sue Mosher's post) but have no idea how to cycle through all the files and extract their filenames without the extension to put in the subject

Here's the code I have so far

Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(0)
With objMail

.Subject = "Filename without Extension"
.To = "Email Address"
.Attachments.Add "c:\scans|filename"
.send

End With


Can anyone help? if so much appreciated

Thanks
 
Joined
Sep 3, 2014
Messages
2
Reaction score
0
Hi All

Worked it out, here it is in case anyone else needs it

Sub SendScans()

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer

'Create an instance of the FileSystemObject

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get the folder object

Set objFolder = objFSO.GetFolder("C:\Scans")

Records = 1

'Loop through each file in the directory and put their names and path into the sheet

For Each objFile In objFolder.Files

Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(0)
With objMail

.Subject = Left(objFile.Name, Len(objFile.Name) - 4)
.To = "??.com"
.Attachments.Add objFile.Path
.Send

End With

Records = Records + 1

Next objFile

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top