Using VBA to implement Excel suicidal features

Source: Internet
Author: User

Once saw a "excel-home" produced "About Excel suicide function" video tutorial, after careful study, I wrote down their code, share in this.

Implementation ideas:

Use VBA to create a hidden name, record the number of times the current workbook has been opened, and automatically delete the workbook if the number of times exceeds the specified value.

Application Range:

1, for VBA development, send someone to test a function (because the beta version, should not be released to the outside, so add the self-deletion function).

2, for other reasons, you need to limit the number of user use.

Event code (THISWORKBOOK):

Determines whether the read run times are required when Excel opens. (First to determine the user name, to avoid debugging, delete their "Labor results")

Private Sub Workbook_Open ()     If "Name "  then        Pager Readopencount        Thisworkbook.save    endIfEnd Sub

Procedure Code (module):

1. Add a hidden name to record the number of open times.

Sub addhiddennames ()    ThisWorkbook.Names.Add Name:="opencount", visible:=False, refersto:=  "=0"End Sub

2, read the number of times the workbook has been opened, if the number of "suicide", did not reach the "number of" +1. (This code, defined is 3 times)

SubReadopencount ()DimICount as ByteICount= Evaluate (Thisworkbook.names ("Opencount"). RefersTo) ICount= ICount +1    IfICount >3  Then        PagerKillthisworkbookElseThisworkbook.names ("Opencount"). RefersTo ="="&ICountEnd IfEnd Sub

3, to achieve "suicide" function, but do not prompt users.

Sub Killthisworkbook ()      with ThisWorkbook         True         . Changefileaccess xlreadonly        Kill  . FullName        . Close    endwithend Sub

Although the above code executes, can get the expected results, but do not forget, "macro" can be disabled, and even some users do not know how to "Enable Macros", which is not in the scope of this article.

Using VBA to implement Excel suicidal features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.