Hello!
I'm currently trying to rename a file and then attach to outlook email but I'm facing an problem.
On the way that I need, I have two diffent cells, one that contains the old file name and another cell that contains the new name.
About renaming files everything is ok, the problem is when I try to attach the file to outlook, I get a error message telling me "Object Required"
Does anyone knows how to fix it?
Thansk!
Image and code below
I'm currently trying to rename a file and then attach to outlook email but I'm facing an problem.
On the way that I need, I have two diffent cells, one that contains the old file name and another cell that contains the new name.
About renaming files everything is ok, the problem is when I try to attach the file to outlook, I get a error message telling me "Object Required"
Does anyone knows how to fix it?
Thansk!
Image and code below


Code:
Sub RenameFile()
Dim OutApp As Object
Dim OutMail As Object
Dim subject As Object
Dim src As String, dst As String, fl As String
Dim rfl As String
Dim tmp1 As String
Dim tmp2 As String
'Folder
src = Range("B3")
'File name
fl = Range("B6")
'Rename file
rfl = Range("D6")
tmp1 = Application.ActiveWorkbook.Path & "\" & fl & ".pdf"
tmp2 = Application.ActiveWorkbook.Path & "\" & rfl & ".pdf"
On Error Resume Next
Name tmp1 As tmp2
If Err.Number <> 0 Then
MsgBox "Error: " & src & "\" & rfl
End If
On Error GoTo 0
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = "doesnt-matter@gmail.com"
.subject = "This is how we do it"
.Body = "This is Body message"
Attachments.Add tmp2
.Display 'Or use .Send
End With
End Sub