Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 29
Default Help needed with automated emailing of workbook

Hello,

I thought I had solved a previous problem that I had with sending an email
when a value in a range got above a certain number, but I haven't as it seems
to send it out regardless.

I am trying to write the code to put in the workbook's beforeclose, but my
code is very rusty, and I am not sure of how to get it to work properly:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M1:M12")
On Error GoTo EndMacro

If rngChange 10 Then GoTo sendeMail


sendeMail:


'(with Thanks to Ron de Bruin)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "(me)"
.CC = ""
.BCC = ""
.Subject = "TEST TEST TEST"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




EndMacro:

End Sub

Can someone help here please? Basically I am trying to say for each value
in the range, if the value is greater than 10 then send an email.
Thanks!



  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Help needed with automated emailing of workbook

I just removed the go to statment and modified the IF statement.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M1:M12")
On Error GoTo EndMacro

If rngChange 10 Then GoTo



'(with Thanks to Ron de Bruin)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "(me)"
.CC = ""
.BCC = ""
.Subject = "TEST TEST TEST"
.Body = "Site(s) in this contract appear over budget. " & _
"Please verify over costs are justified & " & _
"appropriate documentation completed including " & _
"EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
end if
End Sub


"suek" wrote:

Hello,

I thought I had solved a previous problem that I had with sending an email
when a value in a range got above a certain number, but I haven't as it seems
to send it out regardless.

I am trying to write the code to put in the workbook's beforeclose, but my
code is very rusty, and I am not sure of how to get it to work properly:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M1:M12")
On Error GoTo EndMacro

If rngChange 10 Then GoTo sendeMail


sendeMail:


'(with Thanks to Ron de Bruin)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "(me)"
.CC = ""
.BCC = ""
.Subject = "TEST TEST TEST"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




EndMacro:

End Sub

Can someone help here please? Basically I am trying to say for each value
in the range, if the value is greater than 10 then send an email.
Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,344
Default Help needed with automated emailing of workbook

Hi,

Assuming that you wanted to keep the current code just add Exit Sub after:

If rngChange 10 Then GoTo sendeMail

Exit Sub

sendeMail:


--
Thanks,
Shane Devenshire


"suek" wrote:

Hello,

I thought I had solved a previous problem that I had with sending an email
when a value in a range got above a certain number, but I haven't as it seems
to send it out regardless.

I am trying to write the code to put in the workbook's beforeclose, but my
code is very rusty, and I am not sure of how to get it to work properly:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M1:M12")
On Error GoTo EndMacro

If rngChange 10 Then GoTo sendeMail


sendeMail:


'(with Thanks to Ron de Bruin)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "(me)"
.CC = ""
.BCC = ""
.Subject = "TEST TEST TEST"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




EndMacro:

End Sub

Can someone help here please? Basically I am trying to say for each value
in the range, if the value is greater than 10 then send an email.
Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Help needed with automated emailing of workbook

all you have to do is get rid of the goto.

from
If rngChange 10 Then GoTo

to
If rngChange 10 Then

"ShaneDevenshire" wrote:

Hi,

Assuming that you wanted to keep the current code just add Exit Sub after:

If rngChange 10 Then GoTo sendeMail

Exit Sub

sendeMail:


--
Thanks,
Shane Devenshire


"suek" wrote:

Hello,

I thought I had solved a previous problem that I had with sending an email
when a value in a range got above a certain number, but I haven't as it seems
to send it out regardless.

I am trying to write the code to put in the workbook's beforeclose, but my
code is very rusty, and I am not sure of how to get it to work properly:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M1:M12")
On Error GoTo EndMacro

If rngChange 10 Then GoTo sendeMail


sendeMail:


'(with Thanks to Ron de Bruin)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "(me)"
.CC = ""
.BCC = ""
.Subject = "TEST TEST TEST"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




EndMacro:

End Sub

Can someone help here please? Basically I am trying to say for each value
in the range, if the value is greater than 10 then send an email.
Thanks!



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 29
Default Help needed with automated emailing of workbook

No it's still not working. I have modified the code, to put the troublesome
percentages in red, and now it sends out the email every time I close the
workbook, not just when the percentage is higher than it should.

I keep finding reference to target.intersect when I lookup code, but I am
not sure how to use it, and cannot understand the help page, so I am not sure
if this would help or not. I want to send the email only once, regardless
of how many sites are over budget.

It looks like now:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Dim rngCell As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrSite As String
On Error GoTo EndMacro

Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M2:M12")


For Each rngCell In rngChange

If rngCell.Value 10 Then

rngCell.Font.Color = vbRed

Else
rngCell.Font.Color = vbBlack
End If


Next rngCell



Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.to = "(xxx)"
.CC = ""
.BCC = ""
.Subject = "xxx appear over budget"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send


End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




















EndMacro:


End Sub








"Joel" wrote:

all you have to do is get rid of the goto.

from
If rngChange 10 Then GoTo

to
If rngChange 10 Then

"ShaneDevenshire" wrote:

Hi,

Assuming that you wanted to keep the current code just add Exit Sub after:

If rngChange 10 Then GoTo sendeMail

Exit Sub

sendeMail:


--
Thanks,
Shane Devenshire


"suek" wrote:

Hello,

I thought I had solved a previous problem that I had with sending an email
when a value in a range got above a certain number, but I haven't as it seems
to send it out regardless.

I am trying to write the code to put in the workbook's beforeclose, but my
code is very rusty, and I am not sure of how to get it to work properly:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M1:M12")
On Error GoTo EndMacro

If rngChange 10 Then GoTo sendeMail


sendeMail:


'(with Thanks to Ron de Bruin)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "(me)"
.CC = ""
.BCC = ""
.Subject = "TEST TEST TEST"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




EndMacro:

End Sub

Can someone help here please? Basically I am trying to say for each value
in the range, if the value is greater than 10 then send an email.
Thanks!





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Help needed with automated emailing of workbook

Try these changes

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Dim rngCell As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrSite As String
On Error GoTo EndMacro

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)


Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M2:M12")


For Each rngCell In rngChange

If rngCell.Value 10 Then

rngCell.Font.Color = vbRed

On Error Resume Next
With OutMail
.to = "(xxx)"
.CC = ""
.BCC = ""
.Subject = "xxx appear over budget"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed
including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send

End With
On Error GoTo 0

Else
rngCell.Font.Color = vbBlack
End If
Next rngCell
EndMacro:
Set OutMail = Nothing
Set OutApp = Nothing

End Sub


"suek" wrote:

No it's still not working. I have modified the code, to put the troublesome
percentages in red, and now it sends out the email every time I close the
workbook, not just when the percentage is higher than it should.

I keep finding reference to target.intersect when I lookup code, but I am
not sure how to use it, and cannot understand the help page, so I am not sure
if this would help or not. I want to send the email only once, regardless
of how many sites are over budget.

It looks like now:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Dim rngCell As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrSite As String
On Error GoTo EndMacro

Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M2:M12")


For Each rngCell In rngChange

If rngCell.Value 10 Then

rngCell.Font.Color = vbRed

Else
rngCell.Font.Color = vbBlack
End If


Next rngCell



Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.to = "(xxx)"
.CC = ""
.BCC = ""
.Subject = "xxx appear over budget"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send


End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




















EndMacro:


End Sub








"Joel" wrote:

all you have to do is get rid of the goto.

from
If rngChange 10 Then GoTo

to
If rngChange 10 Then

"ShaneDevenshire" wrote:

Hi,

Assuming that you wanted to keep the current code just add Exit Sub after:

If rngChange 10 Then GoTo sendeMail

Exit Sub

sendeMail:


--
Thanks,
Shane Devenshire


"suek" wrote:

Hello,

I thought I had solved a previous problem that I had with sending an email
when a value in a range got above a certain number, but I haven't as it seems
to send it out regardless.

I am trying to write the code to put in the workbook's beforeclose, but my
code is very rusty, and I am not sure of how to get it to work properly:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M1:M12")
On Error GoTo EndMacro

If rngChange 10 Then GoTo sendeMail


sendeMail:


'(with Thanks to Ron de Bruin)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "(me)"
.CC = ""
.BCC = ""
.Subject = "TEST TEST TEST"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




EndMacro:

End Sub

Can someone help here please? Basically I am trying to say for each value
in the range, if the value is greater than 10 then send an email.
Thanks!



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 29
Default Help needed with automated emailing of workbook

Hello,

I thought this had worked, I sent it out this morning with this code, and
when people open and view it and then go to close it, it keeps sending it
out, and out and out....

Why is this so?

"Joel" wrote:

Try these changes

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Dim rngCell As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrSite As String
On Error GoTo EndMacro

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)


Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M2:M12")


For Each rngCell In rngChange

If rngCell.Value 10 Then

rngCell.Font.Color = vbRed

On Error Resume Next
With OutMail
.to = "(xxx)"
.CC = ""
.BCC = ""
.Subject = "xxx appear over budget"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed
including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send

End With
On Error GoTo 0

Else
rngCell.Font.Color = vbBlack
End If
Next rngCell
EndMacro:
Set OutMail = Nothing
Set OutApp = Nothing

End Sub


"suek" wrote:

No it's still not working. I have modified the code, to put the troublesome
percentages in red, and now it sends out the email every time I close the
workbook, not just when the percentage is higher than it should.

I keep finding reference to target.intersect when I lookup code, but I am
not sure how to use it, and cannot understand the help page, so I am not sure
if this would help or not. I want to send the email only once, regardless
of how many sites are over budget.

It looks like now:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Dim rngCell As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrSite As String
On Error GoTo EndMacro

Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M2:M12")


For Each rngCell In rngChange

If rngCell.Value 10 Then

rngCell.Font.Color = vbRed

Else
rngCell.Font.Color = vbBlack
End If


Next rngCell



Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.to = "(xxx)"
.CC = ""
.BCC = ""
.Subject = "xxx appear over budget"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send


End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




















EndMacro:


End Sub








"Joel" wrote:

all you have to do is get rid of the goto.

from
If rngChange 10 Then GoTo

to
If rngChange 10 Then

"ShaneDevenshire" wrote:

Hi,

Assuming that you wanted to keep the current code just add Exit Sub after:

If rngChange 10 Then GoTo sendeMail

Exit Sub

sendeMail:


--
Thanks,
Shane Devenshire


"suek" wrote:

Hello,

I thought I had solved a previous problem that I had with sending an email
when a value in a range got above a certain number, but I haven't as it seems
to send it out regardless.

I am trying to write the code to put in the workbook's beforeclose, but my
code is very rusty, and I am not sure of how to get it to work properly:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M1:M12")
On Error GoTo EndMacro

If rngChange 10 Then GoTo sendeMail


sendeMail:


'(with Thanks to Ron de Bruin)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "(me)"
.CC = ""
.BCC = ""
.Subject = "TEST TEST TEST"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




EndMacro:

End Sub

Can someone help here please? Basically I am trying to say for each value
in the range, if the value is greater than 10 then send an email.
Thanks!



  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Help needed with automated emailing of workbook

You never set the value back to 0 before sending out the e-mail. Try this
change


From:

If rngCell.Value 10 Then


To: add new line just below if statement

If rngCell.Value 10 Then
rngCell.Value = 0

"suek" wrote:

Hello,

I thought this had worked, I sent it out this morning with this code, and
when people open and view it and then go to close it, it keeps sending it
out, and out and out....

Why is this so?

"Joel" wrote:

Try these changes

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Dim rngCell As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrSite As String
On Error GoTo EndMacro

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)


Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M2:M12")


For Each rngCell In rngChange

If rngCell.Value 10 Then

rngCell.Font.Color = vbRed

On Error Resume Next
With OutMail
.to = "(xxx)"
.CC = ""
.BCC = ""
.Subject = "xxx appear over budget"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed
including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send

End With
On Error GoTo 0

Else
rngCell.Font.Color = vbBlack
End If
Next rngCell
EndMacro:
Set OutMail = Nothing
Set OutApp = Nothing

End Sub


"suek" wrote:

No it's still not working. I have modified the code, to put the troublesome
percentages in red, and now it sends out the email every time I close the
workbook, not just when the percentage is higher than it should.

I keep finding reference to target.intersect when I lookup code, but I am
not sure how to use it, and cannot understand the help page, so I am not sure
if this would help or not. I want to send the email only once, regardless
of how many sites are over budget.

It looks like now:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Dim rngCell As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrSite As String
On Error GoTo EndMacro

Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M2:M12")


For Each rngCell In rngChange

If rngCell.Value 10 Then

rngCell.Font.Color = vbRed

Else
rngCell.Font.Color = vbBlack
End If


Next rngCell



Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.to = "(xxx)"
.CC = ""
.BCC = ""
.Subject = "xxx appear over budget"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send


End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




















EndMacro:


End Sub








"Joel" wrote:

all you have to do is get rid of the goto.

from
If rngChange 10 Then GoTo

to
If rngChange 10 Then

"ShaneDevenshire" wrote:

Hi,

Assuming that you wanted to keep the current code just add Exit Sub after:

If rngChange 10 Then GoTo sendeMail

Exit Sub

sendeMail:


--
Thanks,
Shane Devenshire


"suek" wrote:

Hello,

I thought I had solved a previous problem that I had with sending an email
when a value in a range got above a certain number, but I haven't as it seems
to send it out regardless.

I am trying to write the code to put in the workbook's beforeclose, but my
code is very rusty, and I am not sure of how to get it to work properly:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables

Dim shtSummary As Worksheet
Dim rngChange As Range
Set shtSummary = Application.Workbooks("xxx.xls").Worksheets("Summa ry")
Set rngChange = shtSummary.Range("M1:M12")
On Error GoTo EndMacro

If rngChange 10 Then GoTo sendeMail


sendeMail:


'(with Thanks to Ron de Bruin)
Dim OutApp As Object
Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = "(me)"
.CC = ""
.BCC = ""
.Subject = "TEST TEST TEST"
.Body = "Site(s) in this contract appear over budget. Please verify
over costs are justified & appropriate documentation completed including
EOT,variations & additional works."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing




EndMacro:

End Sub

Can someone help here please? Basically I am trying to say for each value
in the range, if the value is greater than 10 then send an email.
Thanks!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Emailing Workbook bart Excel Discussion (Misc queries) 1 November 5th 07 08:05 PM
emailing tabs from a workbook N Herwerden Excel Worksheet Functions 1 October 3rd 06 08:32 PM
emailing a worksheet from a workbook matmich Excel Discussion (Misc queries) 1 February 15th 06 10:08 PM
Emailing a workbook Jmmac04 Excel Discussion (Misc queries) 0 November 22nd 05 05:20 PM
Emailing a workbook with links GuinevereP Excel Worksheet Functions 2 April 7th 05 12:28 AM


All times are GMT +1. The time now is 12:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"