+ Reply to Thread
Results 1 to 19 of 19

receive email automatically when excel file is updated

Hybrid View

  1. #1
    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?
    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 = "[email protected]"
    
        Set OutApp = CreateObject("Outlook.Application")
    
        OutApp.Session.Logon
        Set OutMail = OutApp.CreateItem(0)
    
        With OutMail
            .To = SendTo
            .Subject = ThisWorkbook.sample08 " has been amended"
            .Body = " add a message here"
            .Send
        End With
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    Last edited by royUK; 08-23-2008 at 01:59 PM. Reason: add code tags

  2. #2
    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

           .Subject = ThisWorkbook.sample08 " has been amended"
    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.
    Hope that helps.

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

    Free DataBaseForm example

+ 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