Log in

View Full Version : Alerting email


Wonder84lalala
Aug 28, 2006, 09:58 AM
Hi,

I want to write a small macro in Excel that would send an email when something goes wrong. Can you please help me the VB codes?

Thanks alots!

ScottGem
Aug 28, 2006, 10:10 AM
There are two possibilities here. One possibility would be to use the Hyperlink object with a mailto:[email protected] ([email protected]) to generate an e-mail. The other is to use the Route property to send the workbook. Not sure which would be best for you. Lookup Hyperlink and Route in Excel VBA Help.

Wonder84lalala
Aug 31, 2006, 05:45 AM
Hi Scott,

Thanks for your feedback, but I didn't find any helpful information when I looked into Lookup Hyperlink and Route in Excel VBA Help. Can you show me the examples?

Thanks!

ScottGem
Aug 31, 2006, 06:12 AM
Gee I found the info when I looked. Though I see the HTML editor stripped out part of my instructions; you need to use the Mailto: tag before the e-mail address.

Wonder84lalala
Sep 6, 2006, 06:53 AM
Hi Scott,

I am not sure if we are looking at the same Excel VBA Help, can you please copy and paste what you saw.

Below is what I have found in Excel VBA under Route:

Example
This example sends Book1.xls to three recipients, one after another.

Workbooks("BOOK1.XLS").HasRoutingSlip = True
With Workbooks("BOOK1.XLS").RoutingSlip
.Delivery = xlOneAfterAnother
.Recipients = Array("Adam Bendel", _
"Jean Selva", "Bernard Gabor")
.Subject = "Here is BOOK1.XLS"
.Message = "Here is the workbook. What do you think?"
End With
Workbooks("BOOK1.XLS").Route

ScottGem
Sep 6, 2006, 06:57 AM
Yes, That's what I found. That, as I described, is one possibility.

Wonder84lalala
Sep 6, 2006, 07:32 AM
Are the codes correctly? Where can I place them (under workbook or any tabs) Do I have a create a textbox or label?

Workbooks("BOOK1.XLS").HasRoutingSlip = True
With Workbooks("BOOK1.XLS").RoutingSlip
.Mailto: [email protected]
.Recipients = Array("First Last")
.Subject = "Here is BOOK1.XLS"
.Message = "Here is the workbook. What do you think?"
End With
Workbooks("BOOK1.XLS").Route

ScottGem
Sep 6, 2006, 08:25 AM
The code would be part of a VBA module that could be triggered from a button or key combination.

Wonder84lalala
Sep 7, 2006, 11:06 AM
Scott,

I tried to trigger from a buttom, but I got an error, can you please check the error?

Private Sub CommandButton1_Click()

ActiveWorkbook.HasRoutingSlip = True
ActiveWorkbook.RoutingSlip.Mailto: xlOneAfterAnother

Workbooks("Test.XLS").HasRoutingSlip = True
With Workbooks("Test.XLS").RoutingSlip
.Delivery = xlOneAfterAnother
.Mailto: [email protected]
.Subject = "Here is Test.XLS"
.Message = "Here is the workbook. What do you think?"
End With
Workbooks("Test.XLS").Route

End Sub

ScottGem
Sep 7, 2006, 11:44 AM
I said there are TWO ways to do it. One using Mailto and another using Routing. You are trying to combine both things into one. If you look at the code sample it shows using .Recipients for the To box. You changed the code to something else.

Use one method or the other.