Send file from excel via outlook and change file name via vba

RKay4

New Member
Joined
Aug 25, 2016
Messages
5
I see your posts and wondering if you can help with a simple VBA code. I have the code to send the email from excel and include as attachment, but I want to change the attachment name to be .fullname plus add a cell value to the end of the full name.
This is what I have.

.attachments.Add ActiveWorkbook.FullName & "_" & Range("k1").Value & ".xlsm"

With .fullname by itself it works fine. when I add anything else to try to get the name to change, no attachment.
 
Welcome to Mr Excel forums.
With .fullname by itself it works fine. when I add anything else to try to get the name to change, no attachment.
Because the file must exist in order for it to be attached. Use SaveCopyAs to save a copy of the workbook which includes the K1 cell value in the file name:
Code:
    Dim workbookCopyFullName As String
    workbookCopyFullName = Left(ThisWorkbook.FullName, Len(ThisWorkbook.FullName) - 5) & "_" & Range("K1").Value & ".xlsm"
    ThisWorkbook.SaveCopyAs workbookCopyFullName
and attach this file:
Code:
        .Attachments.Add workbookCopyFullName

     'If necessary, delete the copy
     Kill workbookCopyFullName
 
Upvote 0

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