+ Reply to Thread
Results 1 to 14 of 14

BeforeSave .Save / .SaveAs events not triggering when triggered by macro

  1. #1
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    Hi,

    Bit of a strange one this.

    I have two workbooks, one a Tracker which houses the majority of data and code and the other a Timeline which is largely controlled by the Tracker but also has some small amount of code.

    The Timeline has some code in the BeforeSave event which prevents the user from using SaveAs, backs the file up to an alternate location, etc. When I click on save whilst in the time line the code runs perfectly. However when I initially set up the Timeline using code housed in the tracker the save fails - with no error.
    The .save line in the Tracker triggers the Timeline's BeforeSave but when it goes over each line of code to save and create the backup, nothing happens. I've tried running it with DisplayAlerts and EnableEvents set to true - just to see if any error message shows - but nothing. Perplexed.

    Tracker:
    Please Login or Register  to view this content.
    Timeline:
    Please Login or Register  to view this content.
    Any ideas why the BeforeSave code would run fine when triggered by the user (e.g. File > Save) but not when triggered from another Macro?

    Any help appreciated - as always, TC.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    Have you tried removing this?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    Hi Norie,

    The Error handler isn't triggered but I have annotated it out and run the code again - exactly the same thing happens. Each line of code is stepped through as if all it working okay, no errors - but nothing actually happens, the file isn't saved.

    Confused.

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    Please Login or Register  to view this content.
    The first line will in effect respond to any dialog with its default response. The default response to the message raised by trying to save onto an existing file is 'Do not save'.

  5. #5
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    Thanks for this. Okay, I think I get what you're saying. I didn't realise the default was not to save. It also overwrites fine when the code is prompted from the user clicking on save. Strange.

    How can I force it to overwrite - do I need to use ConflictResolution, though this reads more like it's to do with shared file conflicts rather than overwriting...

    I've had a google but can't see anything specific

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    Why do you need SaveAs instead of Save?

    It seems I have been incorrect - in this instance the default option is not effected.

  7. #7
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    I need to saveas to remove the password protection on the file - so I can then savecopyas to an alternative location - then reinstate the password, allowing the user to maintain control of the same itteration of the file. Basically it's a workaround because savecopyas doesn't allow you to make any changes.

    Hope this makes sense.

  8. #8
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    But could I do this using save? Off to try.

  9. #9
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    Apparently not.

  10. #10
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    I am confused now. Why do you remove the password then save a copy and then reset the password?

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    I think the problem is that your code is trying to overwrite the copy that is running the code and it can not do that.

  12. #12
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    I need to save a copy of the file in an alternative location without the password to open. This allows another offsite area to view copies of the files.

    I need to reinstate the password so that if an 'inhouse user' tries to open the file they cannot, as they don't know the password. Instead they must go through the Tracker to open the underlying timelines - thus the Tracker maintains control of the inhouse file structure.

    It's strange beacus as I said when the user clicks Save the code works perfectly and that is run from within 'thisworkbook' of the timeline form. However if I prompt the code to run from the Tracker (.save, triggers the beforesave) then the code does nothing.

  13. #13
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    Is there any change if you directly call the SaveAs method in preference to using Save and letting the Event procedure do the work?

  14. #14
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: BeforeSave .Save / .SaveAs events not triggering when triggered by macro

    Good idea.

    Works perfectly, so it must be something it doesn't like about running code triggered on an event within another workbook. I even tries running it again with DisplayAlerts enabled but still no messages of any kind.
    It's a bit clunky as it means I'll have to insert the same chunk of code in the Tracker - but I can live with that if it works.

    Strange though. I wonder why it's set up that way...

    Thanks again for the good idea.

+ 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. Problem with Save & Close macro and beforeSave event
    By Danny_ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-18-2013, 04:32 PM
  2. BeforeSave and SaveAs to either save at predefined folder or let the user choose
    By Snyder in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-16-2010, 07:18 PM
  3. How to stop SaveAs command triggering Change_Events?
    By Schwizer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-08-2007, 02:28 PM
  4. Triggering Worksheet Events
    By gnaiggg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-25-2007, 05:31 AM
  5. CREATING E-MAIL ATTACHMENT WITH 'BeforeSave Events' IN CODE
    By Chuckles123 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 09-08-2005, 01:02 PM

Tags for this Thread

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