Announcement

Collapse
No announcement yet.

VBA for outlook to autosend email on login & logout from outlook

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBA for outlook to autosend email on login & logout from outlook

    Hello All,

    I am a end user and as such do not hae much knowledge of VBA.
    What I am looking for is a code which can be use in outlook such that the moment a user login to outlook a mail is triggered out to a set recepient and set subject. Similarly when the user is closing outlook a mail again gets triggered.

    The objective here is capture the users outlook session time.

    I got most of the user on 2003 with a few exception on 2007.

    Kindly advice.

  • #2
    Re: VBA for outlook to autosend email on login & logout from outlook

    Cross posted: http://www.pcreview.co.uk/forums/vba...-t4056033.html (and an older posting at http://www.vbforums.com/showthread.p...a-ID-of-choice)

    Please have another read of the rules you agreed to when you joined the forum. Rules #3...

    3. Do not cross-post without supplying a link to the duplicate question on the other forum.

    Cross posting without adding links to posts on other boards can waste time if similar solutions are provided on more than one board. Please update your post with links to any other threads you started and ensure that any future posts by you comply with the rules.

    Comment


    • #3
      Re: VBA for outlook to autosend email on login & logout from outlook

      Try something based on this:
      Code:
      Private Sub Application_MAPILogonComplete()
          MsgBox "Logged on to Outlook"
      End Sub
      
      Private Sub Application_Quit()
          MsgBox "Outlook exiting"
      End Sub
      Put the code in the ThisOutlookSession module.

      Please update your other threads with a link to this thread, so that people trying to help you on those other forums know that you've posted your question elsewhere and have a possible solution, otherwise they might be wasting their time.

      Comment


      • #4
        Re: VBA for outlook to autosend email on login & logout from outlook

        Thanks cytop for highlighting the miss.
        Yes I have uploaded the same query on the below links.
        http://www.pcreview.co.uk/forums/vba...-t4056033.html
        http://www.vbforums.com/showthread.p...a-ID-of-choice

        However Ozgrid is the only one where I have recived a reply.
        Thanks indeed.

        Comment


        • #5
          Re: VBA for outlook to autosend email on login & logout from outlook

          Thanks john for the code, however I was looking for a code which triggered a mail automatically post login and just after log off.
          I have managed to create the below code, the issue I am facing is that, I am succesfully able to send the mail on login, but everytime i close outlook, i get an error on the second part of the code where it should send a logout mail before exiting.

          Can you help me fix it.
          _______________________________________________________________________________
          Private Sub Application_MAPILogonComplete()
          Dim OutApp As Object
          Dim OutMail As Object
          Set OutApp = CreateObject("Outlook.Application")
          Set OutMail = OutApp.CreateItem(0)
          On Error Resume Next
          With OutMail
          .To = "[email protected]"
          .CC = ""
          .BCC = ""
          .Subject = "Login for the day"
          .Body = ""
          .Attachments
          .Display
          End With
          On Error GoTo 0
          Set OutMail = Nothing
          Set OutApp = Nothing
          End Sub
          _____________________________________________________________________________
          Private Sub Application_Quit()
          Dim OutApp As Object
          Dim OutMail As Object
          Set OutApp = CreateObject("Outlook.Application")
          Set OutMail = OutApp.CreateItem(0)
          With OutMail
          .To = [email protected]
          .CC = ""
          .BCC = ""
          .Subject = "Logout for the day"
          .Body = ""
          .Attachments
          .Display
          End With
          Set OutMail = Nothing
          Set OutApp = Nothing
          End Sub
          ________________________________________________________________________

          Comment


          • #6
            Re: VBA for outlook to autosend email on login & logout from outlook

            Thanks everyone, I figured it out, the code works fine now.
            Got some help from the below link.
            http://www.vbaexpress.com/forum/showthread.php?t=36205


            ______
            Private Sub Application_MAPILogonComplete()
            Dim OutApp As Object
            Dim OutMail As Object
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
            .To = "Amin, Shashikant [ICG-CTS NE]"
            .CC = ""
            .BCC = ""
            .Subject = "Login for the day"
            .Body = ""
            .Attachments
            .Send
            End With
            On Error GoTo 0
            Set OutMail = Nothing
            Set OutApp = Nothing
            End Sub
            Private Sub Application_Quit()
            Dim OutApp As Object
            Dim OutMail As Object
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(0)
            With OutMail
            .To = "Amin, Shashikant [ICG-CTS NE]"
            .CC = ""
            .BCC = ""
            .Subject = "Logout for the day"
            .Body = ""
            .Attachments
            .Send
            End With
            Set OutMail = Nothing
            Set OutApp = Nothing
            End Sub

            Comment


            • #7
              Re: VBA for outlook to autosend email on login & logout from outlook

              Glad you got it working. My code was just a template showing the relevant Outlook event handlers to focus your searches for a solution.

              Comment

              Working...
              X