+ Reply to Thread
Results 1 to 21 of 21

Block from workbook saving from personal workbook macro

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Block from workbook saving from personal workbook macro

    Hi,

    i have code in personal workbook.
    When i am running the code from quick access toolbar:

    Screenshot_6.png

    Please Login or Register  to view this content.
    (personal macro code)

    it is working ok.
    the code is creating new worksheet. (this is for test purposes so please do not ask what is a purpose, i am reviewing csv data in prefered format but code is not important but idea).

    And i would like to prevent user from saving the changes in active workbook (not personal).
    So macro is in personal workbook and i am opening other workbooks to use it.

    I could create somehow workbook_beforesave event from personal sub into activeworkbook.thisworkbook object and block user from saving workbook (??)

    How can i do this?
    Do you have any idea?

    i am not attaching personal workbook because still you would have copy code to your personal workbook

    Best,
    Please help,
    Jacek

  2. #2
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    In other ways,

    how can i pass this code (not allowing to save workbook) from personal workbook macro sub into currently used activeworkbook?

    Please Login or Register  to view this content.

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Block from workbook saving from personal workbook macro

    You need to trap the application-level equivalent event. See Chip's page: http://www.cpearson.com/Excel/AppEvent.aspx
    Rory

  4. #4
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    Wow thank you,

    seems better than approach what i figured out:

    Please Login or Register  to view this content.
    Best,
    Jacek

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Block from workbook saving from personal workbook macro

    Yeah, you never want to do that if it can be avoided.

  6. #6
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    rorya,

    it can be harmful for project ?

    Best,
    Jacek

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Block from workbook saving from personal workbook macro

    Depending on security settings, it may not work at all. And anti-virus may decide it looks suspicious and just remove all your code.

  8. #8
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    thank you rorya,

    you have great knowledge!

    Jacek

  9. #9
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    Ok,

    i am reopening the topic because this is not working.

    To personal workbook i added:

    1. ThisWorkbook:
    Please Login or Register  to view this content.
    2. Module:

    Please Login or Register  to view this content.
    3. Class Module (CExcelEvents - name)

    Please Login or Register  to view this content.
    4. ThisWorkbook (also in personal) - i added code:

    Please Login or Register  to view this content.
    but this is not working. Not triggered.

    Why this is not working?

    Best,
    Jacek

  10. #10
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Block from workbook saving from personal workbook macro

    What are you doing to trigger it? You realise that would stop you saving any workbook?

  11. #11
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    Hi rorya,

    You realise that would stop you saving any workbook?
    Ups i didnt realize. thank you. I think i can in personal workbook during opening any Excel i can set up entire app event to cancel = false to avoid this.

    ----

    i am running macro from button (adding new worksheet) and after that i want to prevent user (me! from saving.
    And this code :

    Please Login or Register  to view this content.
    i thought it should be triggered automatically before save event.

    Best,
    Jacek

  12. #12
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Block from workbook saving from personal workbook macro

    Did you restart excel or manually run the Workbook_open code so that it set up the event listener?

  13. #13
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    Please Login or Register  to view this content.
    when i am restarting Excel (closing all opened instances) the workbook_open code in personal workbook is running and this is setting up event listener.

    But how to trigger it?

    Jacek

  14. #14
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Block from workbook saving from personal workbook macro

    Save a workbook.

  15. #15
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    Not working.

    this code is not working:

    Please Login or Register  to view this content.
    i put it in personal workbook in ThisWorkbook module.

    Best,
    Jacek

  16. #16
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Block from workbook saving from personal workbook macro

    That should be in your class module, not in ThisWorkbook.

  17. #17
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    Hi rorya, this is not working. I do not know what i am doing wrong.

    In personal i added in ThisWorkbook object:

    Screenshot_13.png

    Code in Module1 to run from quick access toolbar in module in personal (to have the macro in all Excels):

    Screenshot_14.png

    In class module:

    Screenshot_15.png

    And now i want to run the code :

    Please Login or Register  to view this content.
    for each workbook after personal macro run.
    If ReadCSV macro was run i should show msgbox before workbook saving.

    How can i achieve this?

    Best,
    Jacek

  18. #18
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Block from workbook saving from personal workbook macro

    mgbox is not valid syntax.

  19. #19
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    thank you rorya,

    ok i do not know why this has started working !

    thank you, great approach !

    One more question:

    Please Login or Register  to view this content.
    i have to add beforesave app event in class because i have in class App declared?

    Best,
    Jacek

  20. #20
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Block from workbook saving from personal workbook macro

    Yes. If you have the class module loaded and click in the left hand dropdown at the top of the main code window, you will see the objects whose events you can use and in the right hand one you will see the events available to the object selected in the left hand dropdown.

  21. #21
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Block from workbook saving from personal workbook macro

    thank you rorya!

+ 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. Replies: 0
    Last Post: 10-20-2016, 11:52 AM
  2. Saving Macros to the Personal Workbook
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-18-2016, 04:03 PM
  3. Problem with saving macro to personal macro workbook
    By JaguerRhye in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-09-2016, 03:43 AM
  4. Saving personal workbook before closing excel
    By Thor Almighty in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2015, 06:27 AM
  5. [SOLVED] Saving Macros in Personal Workbook
    By EPage in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2015, 01:52 PM
  6. Replies: 4
    Last Post: 10-25-2011, 12:35 AM
  7. Running workbook macro from personal workbook
    By mashley in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2009, 08:44 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