• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Email Notifications when excel file modified|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Email Notifications when excel file modified|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosEmail Notifications when excel file…
sp_PrintTopic sp_TopicIcon
Email Notifications when excel file modified
Avatar
nina korneva`
Member
Members

Dashboards
Level 0
Forum Posts: 9
Member Since:
May 10, 2016
sp_UserOfflineSmall Offline
1
October 20, 2016 - 5:23 am
sp_Permalink sp_Print sp_EditHistory

Hi Mynda,

 

I have a shared file that multiple users use and I have created a code that highlight in red a cell that was changed and send an email notification.

However, it sends email every time when each cell is modified. Can the email notification be send when the file is saved and closed?

Also is it possible to add into email who changed the file? Please see attached my file let me know if you can help me.

 

Thank you,

Nina

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1549
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
October 20, 2016 - 12:25 pm
sp_Permalink sp_Print sp_EditHistory

Hi Nina,

Using Worksheet_SelectionChange the VBA is executed every time you move to a different cell.  By using Worksheet_Change you can limit the code execution to only when a cell is changed.  And then by testing the interior colour of the cell (as you did) you can check if its one of the cells you care about.  This code is in the Sheet module.

You can use the Workbook_BeforeClose event to send the email before the workbook is closed.  This code is in the ThisWorkbook module.  I've just created a dummy event handler in there for you to put in whatever code you wish.

The user name can be gotten in a variety of ways.  You can use Application.UserName or Environ("username"). You can use Envrion to get the computer name and domain too.

If you are on a network you can also use calls to WScript to get the username, computer name and domain.

I've included code to do all of this in the Worksheet_Change sub.  Without knowing your environment I don't know if this is sufficient for what you want to do. 

There are others ways to get the username but they require a bit more setup (references in the VBA editor, function declarations) so might be over complicating things.  The simple options above should be fine.  The PC environment variables (accessed with Environ) should be set according to the network username/domain/PC Name and should hopefully be sufficient to identify someone.

regards

Phil

Avatar
nina korneva`
Member
Members

Dashboards
Level 0
Forum Posts: 9
Member Since:
May 10, 2016
sp_UserOfflineSmall Offline
3
October 21, 2016 - 1:36 am
sp_Permalink sp_Print

Hi Phillip,

 

I see the code but how can I execute it? It does not seem to send the email when I close the file.I have just started working with the vba and really need help with it. Also the Application.UserName or Environ("username")   will work and we are in network I am not sure which option is better I just need a short message that file last was modified by that user that is it.

 

Thank you,

Nina

Avatar
nina korneva`
Member
Members

Dashboards
Level 0
Forum Posts: 9
Member Since:
May 10, 2016
sp_UserOfflineSmall Offline
4
October 22, 2016 - 12:50 am
sp_Permalink sp_Print

Good morning,

 

Can you please help me with it?

I really need to make it work as soon as possible.

 

Thanks,

Nina

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1549
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
5
October 23, 2016 - 8:57 pm
sp_Permalink sp_Print sp_EditHistory

Hi Nina,

The workbook I attached to my last reply contained the event code for you to use.  You just need to copy the email code that you were already using into the appropriate event sub.

I have been looking at this over the weekend, it's not as simple as it may appear.  If you send the email when the workbook is closed, you need to be able to check if the workbook has been changed.  Excel provides a way to do this by checking if the workbook has been saved since any changes were made. 

But, if someone makes changes and then saves the workbook, when you check if the file needs saving, Excel will tell you it doesn't, so effectively you end up thinking the file hasn't been changed when in fact it has.

So if you use Workbook_BeforeClose to test for changes, you may miss some.

You may be better off using Worksheet_Change and checking if the affected cell is one you care about, and send the email then.  Of course you could end up with multiple emails.

Another approach is to use both Worksheet_Change and Workbook_BeforeClose. When a cell you are concerned with changes, Worksheet_Change records this (in a public variable) but doesn't send an email. When the workbook is closed Workbook_BeforeClose checks the public variable and sends an email if it sees that a change has occurred.

I'll write something to do this and post it here

Regards

Phil

Avatar
nina korneva`
Member
Members

Dashboards
Level 0
Forum Posts: 9
Member Since:
May 10, 2016
sp_UserOfflineSmall Offline
6
October 24, 2016 - 11:22 pm
sp_Permalink sp_Print

I see the code that you sent and when I changed something in that file and then closed it does not send the email.

How can I fix this?

Avatar
nina korneva`
Member
Members

Dashboards
Level 0
Forum Posts: 9
Member Since:
May 10, 2016
sp_UserOfflineSmall Offline
7
October 26, 2016 - 3:59 am
sp_Permalink sp_Print

Is the code you sent supposed to be working or I need to change something?Please advise.

 

Thank you,

Nina

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1549
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
8
October 26, 2016 - 2:31 pm
sp_Permalink sp_Print sp_EditHistory

Hi Nina,

Yes the workbook I provided has working event code in it.  You just needed to put what code you want into that event handler/sub.

But, as I said in my last reply, this is actually quite complicated to do correctly.  The initial approach could result in either changes not being reported, or emails being sent when in fact no changes were made.

I had to use a combination of different events and track changes using a hidden sheet.

When you open the workbook, you'll only see one sheet in the tabs at the bottom left of your Excel screen.  But if you open the VBA editor (ALT+F11), you'll see there is another sheet called VeryHiddenSheet.  I've set this to be VeryHidden which is a special property that means not only is the sheet not visible from the Excel front end, it can't be unhidden unless you go into the VBA editor.

This new workbook (attached) will track changes correctly on the red cells you are concerned with and send you an email when the workbook is closed.

Of course, VBA must be enabled for the code to work.

Excel can track changes but it does have limitations, but check it out anyway.

regards

Phil

Avatar
nina korneva`
Member
Members

Dashboards
Level 0
Forum Posts: 9
Member Since:
May 10, 2016
sp_UserOfflineSmall Offline
9
November 11, 2016 - 12:44 am
sp_Permalink sp_Print

Can you please remove attachments in this chain?

I receive emails form other people who using it!

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
10
November 11, 2016 - 5:44 am
sp_Permalink sp_Print

Hi Nina,

I removed your email from each file from this topic, you will not receive those messages.

Cheers,

Catalin

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Mynda Treacy, Andy KA, Eric Nyarko, Ric Wade, QSolutions Group
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
jaryszek: 183
Newest Members:
Jennifer Rodriguez-Avila
Khaled Ibrahim
Kiran Supekar
Lisa Myers
Ronald White
Ginette Guevremont
Taryn Ambrosi
Mark Davenport
Christy Nichols
Harald Endres
Forum Stats:
Groups: 3
Forums: 24
Topics: 6530
Posts: 28602

 

Member Stats:
Guest Posters: 49
Members: 32820
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.