+ Reply to Thread
Results 1 to 5 of 5

Event Triggers

  1. #1
    Registered User
    Join Date
    05-21-2014
    Posts
    8

    Event Triggers

    Excel Community,

    I have a worksheet that lists 40+ inventory items with their running total amounts. I used Ron de Bruin's code to send emails from the sheet (it is working great!). Could anyone provide the code for an event trigger so that, when the inventory dips below 15,000 lbs, a reminder email is sent out to buy more?

    Thanks!

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Event Triggers

    Something like this?

    This code looks at Sheet 1, B3, every time something on the sheet changes. If the value in that cell drops below 15000, the code under EMAILORDER will execute. If it's more than 15000, nothing will happen.

    Change the variable titles as desired, or the textbox, or the Event. I put this under Sheet1, not in a module.

    Please Login or Register  to view this content.
    Edit- I had it declared as an integer, use double instead.
    Last edited by Speshul; 06-27-2014 at 11:42 AM.

  3. #3
    Registered User
    Join Date
    05-21-2014
    Posts
    8

    Re: Event Triggers

    I moved she code from module 1 to sheet 2 "total". I also changed the range and changed the sheet name.

    In the debugger I get the pop up, "Run-time error '13': Type Mismatch".

    Any ideas why?

  4. #4
    Registered User
    Join Date
    05-21-2014
    Posts
    8

    Re: Event Triggers

    Sub Send_Range_Or_Whole_Worksheet_with_MailEnvelope()
    Dim AWorksheet As Worksheet
    Dim Sendrng As Range
    Dim rng As Range
    Dim OrderMore As Double

    OrderMore = Sheets("total").Range("J4:J47")

    If OrderMore < "15000" Then GoTo EmailOrder
    Exit Sub

    EmailOrder:

    On Error GoTo StopMacro

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

    'Range that will be sent in email
    Set Sendrng = Worksheets("total").Range("B2:J47")

    'Remember the activesheet
    Set AWorksheet = ActiveSheet

    With Sendrng

    ' Select the worksheet with the range you want to send
    .Parent.Select

    'Remember the ActiveCell on that worksheet
    Set rng = ActiveCell

    'Select the range you want to mail
    .Select

    ' Create the mail and send it
    ActiveWorkbook.EnvelopeVisible = True
    With .Parent.MailEnvelope

    ' Set the optional introduction field thats adds
    ' some header text to the email body.
    .Introduction = "The following powders are below their safety stock inventory levels."

    With .Item
    .To = "[email protected]"
    .CC = ""
    .BCC = ""
    .Subject = "Powder Inventory Stock Levels"
    .Send
    End With

    End With

    'select the original ActiveCell
    rng.Select
    End With

    'Activate the sheet that was active before you run the macro
    AWorksheet.Select

    StopMacro:
    With Application
    .ScreenUpdating = True
    .EnableEvents = True
    End With
    ActiveWorkbook.EnvelopeVisible = False

    End Sub

  5. #5
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Event Triggers

    Adding a .Value to your variable maybe?

    Edit: nope...I'm not sure :\

    Don't know if this is correct syntax but I see (with statements between them of course, but this order)

    Please Login or Register  to view this content.
    should it be

    Please Login or Register  to view this content.
    ?



    Please Login or Register  to view this content.
    I'm still really really not great with VBA yet. Don't judge me!
    Last edited by Speshul; 06-27-2014 at 03:25 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calculate event triggers a macro
    By billpurdom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2013, 06:59 AM
  2. Event Macro that Triggers Cut/Paste
    By dennis0918 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2011, 08:37 AM
  3. Filter change triggers event?
    By ckiraly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2007, 03:54 PM
  4. [SOLVED] BeforeUpdate Event triggers twice
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-04-2006, 04:15 AM
  5. [SOLVED] Event Triggers
    By MVM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-31-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1