+ Reply to Thread
Results 1 to 19 of 19

receive email automatically when excel file is updated

  1. #1
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27

    receive email automatically when excel file is updated

    i would like to know if there is a way to generate automated email whenever excel file is updated by any one.

    Thanks,
    Kiran

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    What do you mean by updated? You can't send an email for each change, so you would need to determine what changes should trigger the macro.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27
    Hi RoyUK,

    I mean when ever the file is saved by someone i would like to receive an email automatically.

    Thanks,
    Kiran

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this

    Please Login or Register  to view this content.
    Right click on the Excel icon, top left & select view code. When the VB Editor opens, set the left hand drop down to Workbook, & find BeforeSave in the right hand drop down. Copy & paste the code into that procedure.
    Last edited by royUK; 08-25-2008 at 11:57 AM.

  5. #5
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27
    Hi RoyUK,

    Sorry for being so dumb, but I could not get where to paste the code. I was able to open a VB editor from the excel sheet by the following menus Tools-->Macro-->Visual Basic Editor.

    From here I could not follow your instructions. "set the left hand drop down to Workbook, & find BeforeSave in the right hand drop down".

    Help is greatly appreciated.

    Thanks,
    kiran

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello kiran654,

    Here is how to save a Workbook Event macro...

    How to Save a Workbook Event Macro
    1. Copy the macro using CTRL+C keys.
    2. Open your Workbook and Right Click on any Worksheet's Name Tab
    3. Left Click on View Code in the pop up menu.
    4. Press ALT+F11 keys to open the Visual Basic Editor.
    5. Press CTRL+R keys to shift the focus to the Project Explorer Window
    6. Press the Down Arrow Key until ThisWorkbook is highlighted in blue.
    7. Press the Enter key to move the cursor to the Code Window
    8. Paste the macro code using CTRL+V
    9. Save the macro in your Workbook using CTRL+S

    Sincerely,
    Leith Ross

  7. #7
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27
    Hi Leith,

    I was able to save the macro.
    In the code provided by RoyUK, i have placed my email address. Then what should I do? i tried to update that excel sheet and then save again, but i did not receive an email.
    just want to make sure if i am not doing something which needs to be done or vice-versa?
    By the way thanks for helping me out in saving the macro

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello kiran654,

    If your Outlook email account hasn't been setup, the email won't go out. Did you set the constant SendTo to your email address?
    Please Login or Register  to view this content.
    If you still have problems, post your workbook for review.

    Sincerely,
    Leith Ross

  9. #9
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27
    I created a sample work book named sample08.xls
    I have created two rows and saved it. Then i created the macro as you said.
    Then i tried to add another row into the sheet and saved it.
    Then i checked my email, but no emails.
    yes, i checked my out look email(my work email is already configured to outlook and i gave my work email in the code below).

    Do you mind checking if the code actually is working?
    Please Login or Register  to view this content.
    Last edited by royUK; 08-23-2008 at 01:59 PM. Reason: add code tags

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Please read the Forum Rules & use Code Tags in future

    Youv'e changed this line unnecessarily ThisWorkBook.Name will pick up the workbook name, your code will error & should be red in the VB Editor

    Please Login or Register  to view this content.
    It should be {code] .Subject = ThisWorkbook.Name & " has been amended"[/code]

    If you amend it and have MS OutLook on your sending PC and placed the code in the correct place then it works.
    Last edited by royUK; 08-23-2008 at 02:06 PM.

  11. #11
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27
    Hi RoyUK,

    I tried it but it did not work for me. Probably I am not doing it right.

    Thanks,
    Kiran654

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Attach the workbook that you have ut the code in.

  13. #13
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27
    Hi RoyUK,

    Here is the excel file with the code attached.
    Thank you very much for your help.

    Thanks,
    Kiran
    Attached Files Attached Files

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You've placed the code in he worksheet not the workbook code module.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27
    hi RoyUK,

    I saved the file on my desktop. Then i added a row and then saved again, but did not receive any email. Only other thing i changed is the existing in the code to my work email id since it is configured to outlook.
    Did it work for you?

    Thanks,
    Kiran

  16. #16
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The code sends an email each time the workbook is saved, no problem here.

  17. #17
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27
    Hi RoyUK,

    I am not sure why but I am not able to get an email when i save it.
    Thanks for your help.

    Thanks,
    Kiran

  18. #18
    Registered User
    Join Date
    08-21-2008
    Location
    USA
    Posts
    27
    Hi RoyUK,

    I pasted your code in the right place now and when i saved it, it asked me if it can send an email. I clicked YES and it did send an email.
    I closed the excel file, re-opened and updated osmething in the file and re-saved it.This time i didn to get any email.
    I thought when i open the file, update something and save it, an email issent automatically.
    help is greatly appreciated

  19. #19
    Registered User
    Join Date
    07-27-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Professional Plus 2010
    Posts
    1

    Re: receive email automatically when excel file is updated

    Hi,

    How can i send to more than 1 email with using the code below ?

    Option Explicit

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim OutApp As Object
    Dim OutMail As Object
    Const SendTo As String = "your email address"

    Set OutApp = CreateObject("Outlook.Application")

    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)

    With OutMail
    .To = SendTo
    .Subject = ThisWorkbook.Name & " has been amended"
    .Body = " add a message here"
    .Send
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
    End Sub

+ 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. An Excel file is missing
    By nicknil in forum Excel General
    Replies: 2
    Last Post: 04-04-2008, 02:14 AM
  2. determining the Directory of an Excel file
    By Ingenieros_en_a in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-28-2007, 05:59 AM
  3. Automatically Save an excel file at a certain time
    By RobbieBobbie23 in forum Excel General
    Replies: 2
    Last Post: 06-26-2007, 02:16 PM
  4. Replies: 0
    Last Post: 06-25-2007, 11:56 AM
  5. Importing data from another excel file automatically
    By rondarat in forum Excel General
    Replies: 10
    Last Post: 03-08-2007, 12:11 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