Fil named after cell K9 and send by mail

KlausW

Active Member
Joined
Sep 9, 2020
Messages
462
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone
I have a small challenge, I use this VBA code to send the file by email. It works well.
But I would like the file to be named after cell K9.
Can anyone help.
Any help would be appreciated.
Best regards
Klaus W

VBA Code:
Sub Rektangelafrundedehjørner2_Klik()

Dim strPath As String
Dim OutlookApp As Object, OutlookMail As Object

On Error GoTo errHandler
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
strPath = Replace(ThisWorkbook.FullName, ".xlsm", ".xlsx")
Application.DisplayAlerts = False
ThisWorkbook.SaveAs strPath, 51
Application.DisplayAlerts = True

With OutlookMail
    .To = Range("k1").Text
    .CC = ""
    .BCC = ""
    .Subject = Range("k9").Value
    .Body = Range("k2").Value
    .Attachments.Add strPath
    .Send
End With

exitHere:
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Application.DisplayAlerts = True
Exit Sub

errHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume exitHere

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try
VBA Code:
strPath = ThisWorkbook.Path & "\" & Range("K9").Value & ".xlsx"

Artik
 
Upvote 0
Solution
Try
VBA Code:
strPath = ThisWorkbook.Path & "\" & Range("K9").Value & ".xlsx"

Artik
Hi Artik, Thank you, just as it should be. Many greetings from Denmark Klaus W
 
Upvote 0

Forum statistics

Threads
1,226,470
Messages
6,191,208
Members
453,648
Latest member
graduateguardian

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