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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.