20 excel files and each 1 is accompanied by a pdf file with a similar name
Revised code will attach pdf if name is same i.e File1.xlsx & File1.pdf
Regarding the original code you posted above, it attaches the file first before deleting the row
Below changes will solve
Option Explicit
Sub Aredeekay()
Dim Fso As Object, objFolder As Object, File As Object
Dim path As String, Fl As String, Flpdf As String
Dim wb As Workbook
Application.ScreenUpdating = False
path = ThisWorkbook.path & "\Test\"
Set Fso = CreateObject("Scripting.filesystemobject")
Set objFolder = Fso.GetFolder(path)
For Each File In objFolder.Files
If File.Name Like "*.xlsx" Then
Set wb = Workbooks.Open(File)
Fl = wb.Name
Flpdf = Replace(Fl, "xlsx", "pdf")
With wb.ActiveSheet
.Rows(1).Delete
End With
wb.save
With CreateObject("Outlook.Application").Createitem(0)
.To = "[email protected]"
.Subject = "Sending File"
.Body = "Hi Please see attached"
.Attachments.Add path & "\" & Fl
.Attachments.Add path & "\" & Flpdf
.Display '.Send
End With
Application.DisplayAlerts = False
wb.Close savechanges:=True
Application.DisplayAlerts = True
End If
Next File
Application.ScreenUpdating = True
End Sub
Bookmarks