Macro button - save as and email

jay-excel

New Member
Joined
Aug 20, 2009
Messages
34
Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I am trying to create a button that when clicked, it will save the file in a new location then send the file as an attachment in an email. I have been playing around with the macro posted below, but have not had very much success (being new at macros, my knowledge is rather limited). <o:p></o:p>
<o:p></o:p>
My goal for the macro is:<o:p></o:p>
<o:p> </o:p>
1. click button<o:p></o:p>
2. the file name is taken from a cell within the workbook <o:p></o:p>
3. file saves to a specified directory<o:p></o:p>
4. after the file is saved, it is sent as an attachment in an email<o:p></o:p>
5. the subject in the email will be the same as the file name<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
So far I have pieced together the following formula:<o:p></o:p>
<o:p></o:p>
---------<o:p></o:p>
Private Sub Sendorderbutton_Click()
Application.Dialogs(xlDialogSendMail).Show arg1:="
email@email.com", _
arg2:=ActiveSheet.Range("Y2")
<o:p></o:p>

fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Excel Files (*.xls), *.xls")
<o:p></o:p>
'If user specified file name, perform Save and display msgbox
If fileSaveName <> False Then
ActiveWorkbook.SaveAs Filename:=ActiveSheet.Range("Y2"), FileFormat:=xlNormal
<o:p></o:p>
MsgBox "Save as " & fileSaveName
End If
End Sub
<o:p></o:p>
<o:p></o:p>
------------<o:p></o:p>
<o:p></o:p>
The problems (among many) that I am having are:<o:p></o:p>
<o:p></o:p>
1. Setting the directory location for the file to be saved.<o:p></o:p>
2. I cannot get the file name to be taken from a cell in the sheet<o:p></o:p>
3. I want the file to saved and named before the email is sent.<o:p></o:p>
<o:p></o:p>
I am aware that the code for saving the file comes after the code for emailing the file. However, given my limited knowledge I was unable to successfully change the order of the two.<o:p></o:p>
<o:p></o:p>
Any help or suggestions would be greatly appreciated. Or if anyone could point me to a similar post or macro that is performing the same function I would be very grateful.<o:p></o:p>
<o:p> </o:p>
Thanks in advance for helping me advance my VBA knowledge.<o:p></o:p>
<o:p> </o:p>
- Jay<o:p></o:p>
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi,

Thanks for the link. Unfortunately however I was unable to locate an example that contained an emailing and saving option. The closest one saved the file in a temp directory then the file was deleted.

Cheers
 
Last edited:
Upvote 0
Hello,

I have come up with the following which seems to work pretty well.

Private Sub Sendorderbutton_Click()
ThisWorkbook.SaveAs Range("M53") & Range("J53")
Application.Dialogs(xlDialogSendMail).Show arg1:="mail@mail.com", _
arg2:=ActiveSheet.Range("Y2")
End Sub



I am experiencing a problem is the file name exists and the user chooses not to replace it.

Thanks.

Jason
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

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