Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 10th, 2008, 03:48 PM
Authorized User
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Emailing from Excel using webquery

I'm having trouble setting my macro up properly so that when a cell reaches a certain value it sends an email to certain employees. These cells are refreshing every 30 minutes or so from a website the spreadsheet is connected to, for whatever reason excel kind of ignores the refreshed values.

Any thoughts?

Here is the coding I am using.

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    If Target.Cells.Count > 1 Then Exit Sub
    On Error GoTo EndMacro
    If Not Target.HasFormula Then
        Set rng = Target.Dependents
        If Not Intersect(Range("C11"), rng) Is Nothing Then
            If Range("C11").Value < 0 Then Sheet19.Mail_with_outlook
        End If
    End If
EndMacro:
End Sub

Sub ABT_with_outlook()
    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 = "[email protected]"
    strcc = "[email protected]"
    strbcc = ""
    strsub = "Important message"
    strbody = "ABT has reached its stop loss." & vbNewLine & vbNewLine & _
              "Please review this position immediately."

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

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Old October 10th, 2008, 04:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there..

There is no asp problem here.. maybe a VBA one???

anyway, this macro worked or never did it?? because IMHO this is the worst way to do it.. why no just do it in the import proccess?? (that is when you have to check for this things.. and no relay on a cell change.. what if someone change it for you???)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old October 13th, 2008, 04:14 PM
Authorized User
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

gbianchi,

Thanks for the reply. The macro has never actually worked, as I intended it that is. When I manually change something it works, but when it downloads/refreshes from the website it does not work(never has).
The reason we do not check during the upload process is because there really is no upload process...the spreadsheet uploads data from a website (not maintained by us).

Thanks
 
Old October 13th, 2008, 08:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

And what about trying another way.. can you just run the macro manually?? In this code, where do it fail?? what line doesn't do what's supposed to do???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old October 14th, 2008, 11:03 AM
Authorized User
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

gbianci,

If I run the macro manually it sends me a message no matter what the cell value is, which obviously defeats the purpose...is there a different way to set up the macro to send an email message if the value has changed?

My problem seems to continue to be the macro only runs when I manually change a cell value...their really is no import process (unless you count the "refresh" of the web inquiry)...so the macro does work it just does not work the way I need/want it to.

If there is another way I am certainly open to suggestions.
 
Old October 14th, 2008, 11:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Could you be a little more clear.. I'm getting confused.. If you run it manually it always send the mail, so your code is no working manually.. In automatic, the code never works, so there is no refresh, or the refresh is not triggering worksheet_change.. did you try with workbook change???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old October 14th, 2008, 12:03 PM
Authorized User
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

gbianci,

Sorry for the confusion. Yes the macro sends an email no matter what the cell contains...I believe this is because the macro does not contain the
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    If Target.Cells.Count > 1 Then Exit Sub
    On Error GoTo EndMacro
    If Not Target.HasFormula Then
        Set rng = Target.Dependents
        If Not Intersect(Range("C11"), rng) Is Nothing Then
            If Range("C11").Value < 0 Then Sheet19.Mail_with_outlook
        End If
    End If
EndMacro:
End Sub

I cannot find this coding in a macro, but it is in the view code sections of each worksheet. The information is refreshing but the refreshing does not trigger the macro. I did try changing to workbook instead of worksheet but had the same results.

Again sorry for the confusion, I hope this helps straighten things out.
 
Old October 14th, 2008, 01:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok.. let's get the work done step by step..

First, let's do the event to work (no matter what happens inside)..

comment out the code, add a msgbox at the first line, and try modifying a cell for yourself, you will see the message popup.. then run your excel refresh, and see if the message pop up again.. If the message fail, then the event is never called and we can work it around from there...

if it called, then the code is bad...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old October 14th, 2008, 02:18 PM
Authorized User
 
Join Date: Oct 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

okay, I realized I was using an incorrect code because it needs to recognize a formula...so I changed the coding to this.

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    If Target.Cells.Count > 1 Then Exit Sub
    On Error GoTo EndMacro
    If Not Target.HasFormula Then
        Set rng = Target.Dependents
        If Not Intersect(Range("C11"), rng) Is Nothing Then
            If Range("C11").Value < 0 Then ABT_with_outlook
    End If
EndMacro:
End Sub

Now when I try to manually change the cell (that is being refreshed every 30 minutes) it comes back with the following message...

Compile error
Block If without End If
 
Old October 14th, 2008, 02:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. you are missing an end if ;)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    If Target.Cells.Count > 1 Then Exit Sub
    On Error GoTo EndMacro
    If Not Target.HasFormula Then
        Set rng = Target.Dependents
        If Not Intersect(Range("C11"), rng) Is Nothing Then
            If Range("C11").Value < 0 Then ABT_with_outlook
        end if
    End If
EndMacro:
End Sub
HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing data from web using WebQuery maxpotters Excel VBA 0 January 18th, 2007 02:02 PM
Emailing from Excel danielharris Excel VBA 0 January 11th, 2006 06:39 PM
Opening and emailing Excel sheet through ASP.Net venterjo ASP.NET 1.0 and 1.1 Basics 0 October 10th, 2005 09:55 AM
dynamic emailing ips2004 JSP Basics 1 December 8th, 2004 01:57 PM
HTML Emailing [email protected] BOOK: Expert One-on-One Access Application Development 1 November 24th, 2004 06:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.