PDA

View Full Version : Send email when changes made



amarkle
05-14-2012, 04:01 PM
We have a document in our office that contains all of our company vehicles and who is currently assigned to them (driving them).

The workbooks are set up by month, with the sheets being each day of the month.

Multiple people have access to edit this information.

We also have a GPS application that we enter this information to for speed tracking purposes.

I am looking to have an email sent to me whenever information is changed in the workbook.

I have spent hours searching Google and have tried multiple VBA codes and forums looking for an answer/code that works.

I am new to VBA codes and have absolutely no clue what I'm doing, so I will also need simplified instructions on how/where to put this code in.

If anyone can solve this issue, the office would thank you. We have a huge problem with our GPS assignments not matching our excel list, because people do not update the GPS database.

I am using Excel 2003 and Outlook 2003.
I have attached a copy of one of our list for anyone that would like to give it a go - since nothing seems to work for me.
8062


Thank you!

mperrah
05-14-2012, 04:51 PM
The following procedure illustrates how to send any worksheet with an address in cell A1 by e-mail. This way you can send each worksheet to a different person.
http://i3.msdn.microsoft.com/dynimg/IC101471.gifNote: Use this macro in a module in the workbook with the worksheets you want to send, not in your Personal Macro Workbook (personal.xls(b)).



Sub Mail_Every_Worksheet()
' Works in Excel 97 through Excel 2007.
Dim sh As Worksheet
Dim wb As Workbook
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim TempFilePath As String
Dim TempFileName As String

TempFilePath = Environ$("temp") & "\"

If Val(Application.Version) < 12 Then
' You are using Excel 97 through Excel 2003.
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You are using Excel 2007
FileExtStr = ".xlsm": FileFormatNum = 52
End If

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

For Each sh In ThisWorkbook.Worksheets
If sh.Range("A1").Value Like "?*@?*.?*" Then
sh.Copy
Set wb = ActiveWorkbook
TempFileName = "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")

With wb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
For i = 1 To 3
.SendMail sh.Range("A1").Value, _
"This is the Subject line"
If Err.Number = 0 Then Exit For
Next i

On Error GoTo 0
.Close SaveChanges:=False
End With

Kill TempFilePath & TempFileName & FileExtStr

End If
Next sh

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub

amarkle
05-15-2012, 09:31 AM
Again, I am completely new to macros and vba codes. I have NO IDEA how to work with them.

I am not able to get this code to work for me.

mperrah
05-15-2012, 10:14 AM
look at Ron De Bruin's site : www.rondebruin.nl (http://www.rondebruin.nl/)
It could be worth a visit. If you don't know which client, you could use cdo.
I looked for code to email excel sheet parts or all. this site helped a lot.