Save workbook to Desktop and email

HughT

Board Regular
Joined
Jan 6, 2012
Messages
113
Office Version
  1. 365
Platform
  1. Windows
I would be grateful if any help could be offered on this - I have searched about but could not find anything.

We have a macro enabled template called 'Referral' that we send out to agents. They complete this and save as a workbook and then email it back. The problem is that the naming convention is random and the email subject line is also random so that it is impossible to catalogue. What I would like to do is :

1. Save the work book to the agent's desktop using the filename in cell N8.
2. Then create and send an email to the office email address using the data in N8 as the subject line with the workbook attached to the email.
3. Code to be embedded in an onscreen button so that all the agent has to do is click it and it works automatically.

Apologies if this is a big ask.

Many thanks

HT
 
Thank you so much! Can the user specify the folder where they want to save it themselves when they save? It may be different for different users.
Sorry to be picky!
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Do you want that to go in their Documents folder?
 
Last edited:
Upvote 0
VBA Code:
Sub HughT()

On Error GoTo errhandler

Dim subjectVal As String

Dim strPath As String

strPath = Environ("USERPROFILE") & "\Documents\"

Set OutApp = CreateObject("Outlook.Application")

Set OutMail = OutApp.CreateItem(0)

With Sheets("Sheet1") 'CHANGE THIS TO THE SHEET NAME

    subjectVal = .Range("N8").Value

    ActiveWorkbook.SaveAs strPath & subjectVal

    With OutMail

        .To = "HughT@mrExcel.com"

        .CC = ""

        .BCC = ""

        .Subject = subjectVal

        .Attachments.Add ActiveWorkbook.FullName

        .Body = "Hi Hugh,"

        .Display

        '.Send      you can send the email without even looking at it

    End With

End With

Set OutMail = Nothing

Set OutApp = Nothing

Exit Sub

errhandler:

MsgBox "Contact Hugh"

End Sub
 
Upvote 0
Absolutely brilliant! Thank you very much for your patience and hard work, this has made a huge difference!
 
Upvote 0
You are absolutely welcome! Let me know if you want to make any other changes or additions to the code! I will be more than happy to help!
 
Upvote 0

Forum statistics

Threads
1,215,756
Messages
6,126,692
Members
449,331
Latest member
smckenzie2016

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