What if Excel can't open a macro?

Source: Internet
Author: User

For example, I want to automatically delete an Excel form after March 2, 2013, and a macro called Macro1 in the table.

  Specifically as follows:

Sub Macro1 ()

Private Sub Workbook_Open ()

Application.DisplayAlerts = False

Dim Datee as Date

Datee = #3/2/2013#

If Date > Datee Then

Activeworkbook.changefileaccess xlreadonly

Kill Activeworkbook.fullname

Thisworkbook.close False

End If

End Sub

But this macro cannot be executed, March 4, 2013 This Excel form has not been deleted! I am not the computer administrator, is the user this does not affect?

  Delete the first sentence of the macro and turn it into:

Sub Workbook_Open ()

Application.DisplayAlerts = False

Dim Datee as Date

Datee = #3/2/2013#

If Date > Datee Then

Activeworkbook.changefileaccess xlreadonly

Kill Activeworkbook.fullname

Thisworkbook.close False

End If

End Sub

Then put the macros under the ThisWorkbook of Excel

What does the name of the macro take? What do I do when I finish typing? What macro name do you want to view the source code?

The macro name is Workbook_Open, a process built into Excel. Execute the macro when you open the file ...

If you open the date more than 3/2/2013, the file is deleted when it is opened.

You can copy this code into any empty file, test it, and remember not to put it in your important file to test.

See the Red Code press ALT+F8 can

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.