Results 1 to 5 of 5

Thread: [RESOLVED] Autogeneration of an email dependant on time criteria

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2012
    Posts
    27

    Resolved [RESOLVED] Autogeneration of an email dependant on time criteria

    Hi guys,

    I have set up a windows scheduler even to open a specific file every friday at 9.30am.

    I now would like to set up a workbook_open event which generates an email when the scheduler opens the file.

    I dont want the email to generate every time the work book is open.

    Does anyone have any sample code for me? I am interested in determining time workbook opened and day, and I am also unsure of the code required to send an email.

    Any assistance would be much appreciated:



    *update*


    Got this far.

    I want the email to be sent only if the workbook is opened between the times 9:25 and 9:35am . I have entered these times into the worksheet as ranges in cells: LTime (9:25) and UTime (9:35) . Formatted them as times.

    Generation of email works. Only remaining issue is that the statement:


    If LTime > dTime > UTime keeps on evaluating to false.

    Does anyone know why this keeps on evaluating to false.





    Sub Workbook_Open()


    Dim dTime As Date

    Call Definitions

    dTime = TimeValue(Now)

    Dim LTime As Date

    Dim UTime As Date

    LTime = wsConsole.Range("LTime")
    UTime = wsConsole.Range("UTime")

    LTime = TimeValue(LTime)
    UTime = TimeValue(UTime)


    If LTime > dTime > UTime Then

    Call Send_Email_Using_Keys

    Else: Call Open_Book

    End If

    End Sub


    Thanks
    Last edited by InderpalHothi; Aug 22nd, 2012 at 10:31 AM. Reason: update

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jul 2012
    Posts
    27

    Re: Autogeneration of an email dependant on time criteria

    *update above*
    Last edited by InderpalHothi; Aug 22nd, 2012 at 10:32 AM.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Autogeneration of an email dependant on time criteria

    try more like
    Code:
    If Time > "9:25" And Time < "9:35" Then
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2012
    Posts
    27

    Re: Autogeneration of an email dependant on time criteria

    cheers, problem sorted.

    Used :

    If Utime>dTime and Dtime>Ltime

    etc

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Autogeneration of an email dependant on time criteria

    problem sorted.
    great, pls mark resolved
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width