combine current codes

sovereign

Board Regular
Joined
Jul 10, 2012
Messages
102
Hi,

i have an excell sheet that my workshop guy fills out when he is checking a car.

it has a few functions and i am curious if i can combine a couple of bits of code:

This bit of code send an email when a box is ticked to request a Tyre (at the moment it has to be done for each Tyre)

Code:
Sub mail()
 
Dim objOutlook As Object
 Dim objOutlookMsg As Object
 Set objOutlook = CreateObject("Outlook.Application")
 Set objOutlookMsg = objOutlook.CreateItem(0)
 With objOutlookMsg
    .To = "andrewb@sauto.co.uk"
    .Subject = "tyre order sovereign"
    .Body = "hi Can i please confirm an order for" & vbNewLine & vbNewLine & "1x " & Worksheets("Sheet1").Range("g10").Value & vbNewLine & vbNewLine & "Reg No:" & Worksheets("Sheet1").Range("H2").Value
    .Send
     End With
     SendMessage = "Your message was sent successfully."
End Sub

And this bit of code saves and emails the whole sheet as a pdf.

Code:
Sub saveandclose()
Dim MyPath As String




Application.DisplayAlerts = False
ActiveWorkbook.saveas Filename:="temp.xlsx"
MyPath = "I:\fleet\Group " & Range("B8").Value & "\" & Range("H2").Value & " - " & Range("B4").Value & " " & Range("E4").Value & "\Check sheet\" & Format(Date, "dd.mm.yy") & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=MyPath
Workbooks.Open Filename:="I:\Check Sheetmacro tin.xltm"




Dim objOutlook As Object
Dim objOutlookMsg As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
.To = "andrewb@sauto.co.uk; deans@sauto.co.uk"
.Subject = "New Check Sheet"
'.Attachments.Add ("I:\Users\andrewb.SA\Documents\temp.xlsx")
.Attachments.Add (MyPath)
.Send
End With
SendMessage = "Your message was sent successfully."




Workbooks("temp.xlsx").Close
Application.DisplayAlerts = True
End Sub

What i would like to happen is when you save the document it looks like whether there is a tick in the box then adds the tyre sizes and counts the amount.

so basically if it needs a Tyre it send two emails one 'as is with the check sheet' and then one with for example '' '2' x '215/55/16' and the reg''
 

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.

Forum statistics

Threads
1,213,535
Messages
6,114,198
Members
448,554
Latest member
Gleisner2

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