Attach all files in folder to email except one

Hasuthika

New Member
Joined
Jan 15, 2018
Messages
1
Hello all,

I'm looking for a vba code which will attach all files in a specific folder except for one ending with .xlsm.

The code which is Bold is the code which attaches all files in that specific folder to the email.
I've got this code now:

Sub Mail()

Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim StrFile As String
Dim StrPath As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

StrPath = Range("L55") & ""

strbody = "Text"

On Error Resume Next
With OutMail
.Display
.To = Range("L57")
.CC = "test@test.nl"
.BCC = ""
.Subject = Range("N4")
.HTMLBody = strbody & .HTMLBody
StrFile = Dir(StrPath & "*.*")
Do While Len(StrFile) > 0
.Attachments.Add StrPath & StrFile
StrFile = Dir
Loop

End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top