Save before send

HeKr

New Member
Joined
Sep 27, 2004
Messages
18
Hello to all,

I've got the following challange:
I have a excel sheet (called XXXX) which people send to me. I have to collect the data of these sheets in 1 big sheet.

The sending part works ok with the code:

Code:
Activeworkbook.sendmail Recipients:= "Me@home.com", _
subject:= "XXXX"

All the files I receive have the same filename (XXXXX) so I can't put them in the same folder on my pc without changing manual the name.
What I like to do is make (with your help) a macro that changes the name of the file in XXXX + date + time (this should be rather unique), send this file with the above code, delete the unique filename and return to my original file called XXXX

I hope this is clear enough to give me a hand

BEst regards

Henk KRuizinga
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I think this is what you want. If you do not want to keep the file you can use 'Kill Fname' to delete it. Make sure your original file has been saved.
Code:
Sub test()
    Dim Fname As String
    Dim MyDate As String
    '--------------------------------------
    '- current date & time
    MyDate = Format(Now, "dd-mm-yy hh-mm")
    '- file name
    Fname = ActiveWorkbook.Name
    Fname = Left(Fname, Len(Fname) - 4) _
        & MyDate & ".xls"
    '- Save As
    ActiveWorkbook.SaveAs FileName:=Fname
    '- send mail
    ActiveWorkbook.SendMail _
        Recipients:="Me@home.com", Subject:="XXXX"
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,216
Messages
6,189,675
Members
453,563
Latest member
Aswathimsanil

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