Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default E-mail if Cell B33 = Yes

Here is a description of what I'm trying to accomplish:

I have a workbook that contains one sheet (sheet 1). This sheet has
formulas that retreive data from an external source via an Excel Add
In. When the sheet is opened the calculations are made. If the
calculations made do not meet specifications I would like to send an e-
mail alert via Outlook informing the correct users. In this particular
sheet cell B33 will display a No if the e-mail alert does not need to
be sent and Yes if the alert needs to be sent. I would like to create
one macro that does both the data verification (check for Yes or No)
and send the e-mail. I would like this macro to run automatically when
the workbook is opened. I then plan to set it up as a scheduled task
to run every 8 hours.

I think that my e-mail code is correct but I am struggling with to Yes/
No verification part. I also would like to know how to run the macro
automatically when the workbook is opened. Below you'll find the code
that I have for the one macro that I have created. Would anyone be
able to help me with this? I am a newbie to Excel/VBA so forgive me
for my ignorance.

Thanks

Justin


Here is my code so far.....

Sub modEmail()

If Worksheets("Sheet1").Range("B33") = Yes Then

Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String
Dim strsub As String, strbody As String

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

strto = "My E-mail Address"
strcc = ""
strbcc = ""
strsub = "My Subject"
strbody = "This is an automated message."

With OutMail
.To = strto
.CC = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
.Send
End With

Set OutMail = Nothing
Set OutApp = Nothing

End If
Close Workbook

Else
Exit Sub

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default E-mail if Cell B33 = Yes

"Yes"
or to account for case yes, YES, etc

If ucase(Worksheets("Sheet1").Range("B33")) = "YES" Then
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
Here is a description of what I'm trying to accomplish:

I have a workbook that contains one sheet (sheet 1). This sheet has
formulas that retreive data from an external source via an Excel Add
In. When the sheet is opened the calculations are made. If the
calculations made do not meet specifications I would like to send an e-
mail alert via Outlook informing the correct users. In this particular
sheet cell B33 will display a No if the e-mail alert does not need to
be sent and Yes if the alert needs to be sent. I would like to create
one macro that does both the data verification (check for Yes or No)
and send the e-mail. I would like this macro to run automatically when
the workbook is opened. I then plan to set it up as a scheduled task
to run every 8 hours.

I think that my e-mail code is correct but I am struggling with to Yes/
No verification part. I also would like to know how to run the macro
automatically when the workbook is opened. Below you'll find the code
that I have for the one macro that I have created. Would anyone be
able to help me with this? I am a newbie to Excel/VBA so forgive me
for my ignorance.

Thanks

Justin


Here is my code so far.....

Sub modEmail()

If Worksheets("Sheet1").Range("B33") = Yes Then

Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String
Dim strsub As String, strbody As String

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

strto = "My E-mail Address"
strcc = ""
strbcc = ""
strsub = "My Subject"
strbody = "This is an automated message."

With OutMail
.To = strto
.CC = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
.Send
End With

Set OutMail = Nothing
Set OutApp = Nothing

End If
Close Workbook

Else
Exit Sub

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default E-mail if Cell B33 = Yes

I changed my code to the following, does it look correct? Thanks for
your help.

Sub modEmail()

If Worksheets("Sheet1").Range("B33") = "Yes" Then

Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String
Dim strsub As String, strbody As String

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

strto = "My E-mail Address"
strcc = ""
strbcc = ""
strsub = "CSU Inventory Gain"
strbody = "This is an automated message."

With OutMail
.To = strto
.CC = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
.Send
End With

Set OutMail = Nothing
Set OutApp = Nothing
End If
Close Workbook

Else
Exit Sub
Close Workbook

End Sub

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
Convert to HTML and e-mail selection as the body of the e-mail. ryanmhess Excel Programming 5 April 16th 09 01:28 AM
Error: cannot load the mail service. Check your mail installation. Brad Bowser Excel Discussion (Misc queries) 0 December 20th 05 10:03 PM
General mail failure when sending e-mail from Excel Adrienne Excel Discussion (Misc queries) 5 November 4th 05 12:59 PM
Creating TWO-WAY E-Mail Attachments with 'BeforeSave Events' in Code for 2nd E-Mail Chuckles123[_112_] Excel Programming 0 September 8th 05 05:56 PM


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

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

About Us

"It's about Microsoft Excel"