+ Reply to Thread
Results 1 to 25 of 25

Disable VBA codes in the file after a certain date

  1. #1
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    769

    Disable VBA codes in the file after a certain date

    Hi everybody,
    Could you help me in my question,please?
    I have an Excel file with VBA which runs various macros. I want to be able to put one code into it to stop it running after a certain date.
    I need one code to disable all VBA codes( modules,forms and worksheet events) and make the file run without codes.
    To make the VBA in the file work again,I should change the expiration date to another date.
    I don`t want any messages to appear.
    I suggest to put the code in workbook open event.
    Note: VBA project is password-protected
    Any ideas?

    Thanks.
    Last edited by leprince2007; 01-21-2019 at 07:37 AM.

  2. #2
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Disable VBA codes in the file after a certain date

    This should help:
    https://www.mrexcel.com/forum/excel-...tain-date.html
    Click the * to say thanks.

  3. #3
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    769

    Re: Disable VBA codes in the file after a certain date

    Thank you Mr PaulM100 for your help
    I have seen this post before.This is not what I want because It requires to put the code in every sub.
    This is what I ask for:
    "I need one code to disable all VBA codes( modules,forms and worksheet events) and make the file run without codes."

  4. #4
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: Disable VBA codes in the file after a certain date

    I don't think you'll be able to do this, each Sub is going to have to check *something* to know if it can run or not.

  5. #5
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Disable VBA codes in the file after a certain date

    Or.....in the workbook open event put code to check the date and if > whatever limit you require then save the workbook as a .xlsx and delete the existing .xlsm.....no mode code.

    The trouble with that is there is no recovery, once it's removed all the VBA it's gone.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,069

    Re: Disable VBA codes in the file after a certain date

    Oops double posted.

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,069

    Re: Disable VBA codes in the file after a certain date

    I agree with PaulSP8
    However rather than putting the code into all subs, you could create a global boolean variable, & have each sub check the variable at the start of the code.

    @BellyGas, that would need a saveas, so the original workbook would still be available.

  8. #8
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Disable VBA codes in the file after a certain date

    It would, but you could put all the code to complete the operation in a module, export that module at the start of the operation, create a new excel file, import the module with the code to saveas and delete in it....close the existing xlsm and run the code newly imported into the new workbook....which then saveas's and deletes the workbook with the code in it. You'd be left with an xlsx version of the workbook that needs code disabled in and another workbook that doesn't do anything at all except save an xslm as xlsx and deletes the xlsm. Either way, the functional code to be disabled is most definitely disabled.

  9. #9
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Re: Disable VBA codes in the file after a certain date

    If the code is vital for the workbook, what is the point of just deleting the code. Why not just delete the file?

  10. #10
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    769

    Re: Disable VBA codes in the file after a certain date

    Thank you all guys for your help

    Quote Originally Posted by Fluff13 View Post
    I agree with PaulSP8
    However rather than putting the code into all subs, you could create a global boolean variable, & have each sub check the variable at the start of the code.

    @BellyGas, that would need a saveas, so the original workbook would still be available.
    Mr.Fluff13,Could you give me the code to do this?
    Note: I don`t want to delete the file.I just want to disable vba codes until I get into the code again and change the expiration date.

  11. #11
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,069

    Re: Disable VBA codes in the file after a certain date

    At the very top of a regular module (before any code) put
    Please Login or Register  to view this content.
    In the This workbook module, something like
    Please Login or Register  to view this content.
    And in every single procedure add this line
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413
    Very nice Fluff

  13. #13
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    769

    Re: Disable VBA codes in the file after a certain date

    Quote Originally Posted by Fluff13 View Post
    At the very top of a regular module
    Thank you for your solution but this code doesn't work with UDF
    Here is my code:
    In workbook open event:
    Please Login or Register  to view this content.
    in module:
    Please Login or Register  to view this content.
    In UDF:
    Please Login or Register  to view this content.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,069

    Re: Disable VBA codes in the file after a certain date

    You have declared expiry in the ThisWorkBook module, it needs to go in a regular module

  15. #15
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    769

    Re: Disable VBA codes in the file after a certain date

    Do you mean that I should repeat the whole code in thisworkbook to every module?
    Show me the right code,please

  16. #16
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Disable VBA codes in the file after a certain date

    No, the public expiry as boolean needs to be at the top of any ordinary module, NOT the workbook module. And you'll only need it once.

  17. #17
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Disable VBA codes in the file after a certain date

    This line:

    Please Login or Register  to view this content.
    Should be placed only ONCE in ANY SINGLE regular module.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  18. #18
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,069

    Re: Disable VBA codes in the file after a certain date

    Quote Originally Posted by leprince2007 View Post
    Do you mean that I should repeat the whole code in thisworkbook to every module?
    Show me the right code,please
    In ThisWorkbook
    Please Login or Register  to view this content.
    At the very top of a regular module (but only one module)
    Please Login or Register  to view this content.
    in your code/function
    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    769

    Re: Disable VBA codes in the file after a certain date

    Thanks for your code Mr.Fluff13 ,it works but the UDF shows "0",I should edit all cells that contain this UDF or its referenced range to make it recalculate.

  20. #20
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,069

    Re: Disable VBA codes in the file after a certain date

    It won't recalculate if the expiry date is passed, which is what you asked for.

  21. #21
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    769

    Re: Disable VBA codes in the file after a certain date

    No.I extended the expiration date but the UDF doesn't recalculate.It requires me to re-enter the UDF in cells or edit its range.
    I want it to recalculate by itself.
    I think this happens because of the UDF functionality: If you edit the code of the UDF ,You should re-enter it again in cells.
    I created a simple UDf.see the attachment
    Attached Files Attached Files

  22. #22
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,069

    Re: Disable VBA codes in the file after a certain date

    This has nothing to do with preventing the code from running.
    If you have functions that are not working the way you want, then you need to start a new thread.

  23. #23
    Forum Contributor
    Join Date
    02-24-2015
    Location
    Egypt
    MS-Off Ver
    Office 365 ProPlus
    Posts
    769

    Re: Disable VBA codes in the file after a certain date

    It`s a simple UDF (no1*no2).
    Your code doesn't work with any UDF.
    How to make it work?

  24. #24
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,069

    Re: Disable VBA codes in the file after a certain date

    If you change the expiry date to 22-Jan then it will prevent the UDF from working & you will get #N/A values, whenever the function runs.

  25. #25
    Registered User
    Join Date
    07-04-2019
    Location
    Iran
    MS-Off Ver
    2019
    Posts
    1

    Re: Disable VBA codes in the file after a certain date

    Hi, You must use from "Application.Calculate" in workbook_Open Code,
    Sheet automatic update, when open file

+ 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. How to disable warnings when saving a .xlsm file as a .xlsx file
    By audax in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-28-2018, 03:58 AM
  2. Modify my VBA codes in attachment file
    By PRADEEPB270 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-31-2017, 05:31 AM
  3. Vba to run some codes then save file to different filenames
    By bezbid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2016, 02:42 AM
  4. CSV file - zip codes that begin with a zero
    By kmarie630 in forum Excel General
    Replies: 2
    Last Post: 09-24-2014, 11:04 AM
  5. Replies: 0
    Last Post: 03-11-2014, 08:18 AM
  6. VBA Codes for file open
    By vinwin06 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2011, 10:25 AM
  7. Replies: 12
    Last Post: 06-07-2011, 04:17 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