Save File Name Based Off A Cell And Then Draft Up Email On Outlook

rameezl17

Board Regular
Joined
Mar 6, 2018
Messages
105

Hi All,

I have each of the codes to do what I said above...however I cant make them work together.

I want the code to:
First - Save excel file based on Cell C:6 Second - Draft Up An Email Automatically in Outlook Third - But I dont want it to send automatically, I just want it to draft it open and pop up for the user.
This is what I have so far:

Sub SendEmail()


Name = Range("C6").Value ActiveWorkbook.SaveAs Filename:=Name

Dim OutApp As Object Dim OutMail As Object
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.to = "example email"
.CC = ""
.BCC = ""
.Subject = "Form"
.Body = "Test"
.Attachments.Add ActiveWorkbook.FullName
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
</code>End Sub
Any help would be greatly appreciated Thank you!

 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hello there! You were not too far off at all. You need to specify where the file is being saved in the first instance and then display when creating the email.

Code:
Sub SendEmail()

Name = Range("C6").Value
ActiveWorkbook.SaveAs Filename:="H:\" & Name & ".xlsm", FileFormat:= _
  xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
 , CreateBackup:=False

Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.to = "example email"
.CC = ""
.BCC = ""
.Subject = "Form"
.Body = "Test"
.Attachments.Add ActiveWorkbook.FullName
.display
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,085
Messages
6,123,030
Members
449,092
Latest member
ikke

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