how to limit the day to open excel file by VBA

nhnn1986

Board Regular
Joined
Oct 12, 2017
Messages
92
Hi all

I have excel file data.xlsm and share to another one in my company

Now i want another one can only open file if today < 30/08/2019 (day format as dd/mm/yyyyy)
If Today > 30/8/2019 will have notice: "File has expiry date"

Please help me to do this by macro VBA.
Thanks./.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try

Code:
Sub workbook_open()
If Date >= "30/08/2019" Then MsgBox "file has expired"
ActiveWorkbook.Close
End Sub

remembering, of course that if a person disables macros, it won't take effect.
 
Last edited:
Upvote 0
Many thanks M

I have another proplem: The date expired is the value in sheets "main", range(A10). This mean I will type 30/08/2019 in sheets(main).range(A10)

So how to work my proplem with VBA code?

Thanks./.
 
Upvote 0
Use

Code:
Sub workbook_open()
If Date >= Sheets("main").range("A10").value Then MsgBox "file has expired"
ActiveWorkbook.Close
End Sub
 
Upvote 0
Great code Michael M

I share file with another one but there's finals problem is: Someone have computer with diffrience format date
some computer format as: dd/mm/yyyy (like 30/08/2019), but some computer format mm/dd/yyyy (like 08/30/2019).

So code can't work with computer format like: mm/dd/yyyy. Is there has solution to solved this?

many thanks./.
 
Upvote 0
Shouldn't matter which format it's in, if you are using a cell value and that value is relevent to the regional settings !
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top