I created a macro to send multiple invoices, one per email. I need the email subject to be a part of the file name.
It worked with the first file but then it takes that as fixed. I tried to Do While
with the second variable (file1
) but didn't work.
File name for reference: US21_US61_0000_6460069666_YBF2_6203963322_ZB34_00_0
Sub todo()
'Outlook should be opened
Dim OutApp As Object
Dim OutMail As Object
'Opens APP Outlook
Set OutApp = CreateObject("Outlook.Application")
On Error Resume Next
'Improve performance
Application.ScreenUpdating = True
'Path from the computer where it is used
mypath = "C:\Users\natudiaz\Downloads\Invoices\US\"
'Takes files from extension consider pdf or excel
myfile = Dir(mypath & "*.pdf*")
myfile1 = Mid(myfile, 16, 10)
Do While myfile <> ""
'Makes iterations
'Creates email
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = "natudiazci@gmail.com"
.CC = ""
.BCC = ""
.Subject = "INV:" + myfile1
.Body = "To the Team"
.Attachments.Add (mypath + myfile)
.Display
.Send
.ReadReceiptRequested = True
End With
'Next
myfile = Dir
Loop
Application.ScreenUpdating = False
End Sub