KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 462
- Office Version
- 2016
- Platform
- 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
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