VBA Send and Save

Sovereignty9

New Member
Joined
Sep 21, 2016
Messages
10
Can anyone help me??

Please look at the code below vba coding I have used on a work spreadsheet. First lot of coding Is the main coding I want rectified however I'm struggling with the automated save bit, and I do not want it too be a temporary copy that is deleted. I want the code to ensure that when the assigned button is clicked to automatically save it to a certain location as "Rosti Sills Delivery Check DDMMYYY". You can see from the code below send and save that I have got this to happen on a stand alone save button but unable to make it work when send an email at the same time.

Can anyone please help and suggest some changes to get this working as required.

Much appreciated

JoeJoe



Sub EmailandSaveCellValue()

'Variable declaration
Dim oApp As Object, _
oMail As Object, _
WB As Workbook, _
FileName As String, MailSub As String, MailTxt As String

'************************************************* ********
'Set email details; Comment out if not required
Const MailTo = "ben.kirby2@plasticomnium.com; ben.kirby@plasticomnium.com; dominic.hardy@plasticomnium.com; andy.wilson@plasticomnium.com; damian.lee@plasticomnium.com; mevans@plasticomnium.com; gbowley@plasticomnium.com"
Const MailCC = ""
Const MailBCC = ""
MailSub = "Rosti Sills Tracking "
MailTxt = "Hi All," & vbCrLf & vbNewLine & "Please find attached the Rosti sills tracking and handover." & vbCrLf & vbNewLine & "Regards" & vbCrLf & vbNewLine & "GoodsIn" & Chr(10) & Chr(10) & Chr(10)
'************************************************* ********

'Turns off screen updating
Application.ScreenUpdating = False

'Makes a copy of the active sheet and save it to
'a temporary file
ActiveWorkbook.Save
Set WB = ActiveWorkbook
FileName = ("FileName")
On Error Resume Next
Kill "C:" & FileName
On Error GoTo 0
WB.SaveAs FileName:="D:\Personal\measham.goodsin\Desktop\Rosti Delivery Checks\Sent" & FileName

'Creates and shows the outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
.To = MailTo
.Cc = MailCC
.Bcc = MailBCC
.Subject = MailSub
.Body = MailTxt
.Attachments.Add WB.FullName
.Display
End With

'Deletes the temporary file
WB.ChangeFileAccess Mode:=xlReadOnly
Kill WB.FullName
WB.Close SaveChanges:=False

'Restores screen updating and release Outlook
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub




Private Sub CommandButtonSave_Click()
s = ActiveWorkbook.FullName
ActiveWorkbook.SaveAs FileName:=Left(s, Len(s) - 5) & " " & Format(Date, "ddmmyyyy") & ".xlsm", FileFormat:=52
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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