Problem when renaming and attaching file to outlook

Alsiro

New Member
Joined
Jun 1, 2014
Messages
17
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

gg7FBDG.png


eZEkpyT.png



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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,216,111
Messages
6,128,899
Members
449,477
Latest member
panjongshing

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