Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default How to time-limit an Excel file installation



Hi Gord

OK Thanks for your help. I've inserted the module into my wb with this
as the code :


Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 1

Sub TimeBombMakeReadOnly()
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub


i hope this is how it's meant to be. I haven't changed anything ,
although I made it one day so that I can see if it works by tomorrow.

I have a small question :

I really need this routine to start counting down as soon as the wb is
opened for the first time , on any machine. Does the macro have to be
run to set it working on each machine? If so , it sort of defeats the
object...!

Also , could you suggest some code to bring up a message box to show the
wb has expired?

Thanks

Colin




In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
See in-line responses..............

On Fri, 30 Nov 2007 13:35:38 +0000, Colin Hayes
wrote:


Hi

OK Thanks. I thought I'd try the one below.

I have a couple of questions though , if you could advise ;

The workbook it's protecting is called 'Receipts' - do I need to put
this anywhere in the code?


No. Thisworkbook is the workbook you are running the Sub on.

If I use this on more than one wb , do I need to change the name of the
file it stores , so as not to overwrite it.


No changes necessary as far as I can tell.....Thisworkbook refers to whatever
workbook the code is in.

I assume the file it is
storing is 'Expiration date'. It's not clear to me where it stores the
file....


Expiration Date is a named range which holds the date to expire. The code
creates this named range.

The line...........Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 90 must be

placed above the line..........Sub TimeBombMakeReadOnly()

Also , I'm not sure where I should be placing the code in the workbook.
Under the tab at the bottom , or under the Excel symbol at top-left of
the sheet...?


Alt + F11 to open VB Editor

CTRL + r to open Project Explorer if not visible.

Right-click on your workbook and InsertModule.

Paste code into that module with the edits above.

Save the workbook then run the macro which sets the time to expire as 90 days
from when you run the macro.

Have you downloaded the sample workbook from Chip's site to see how he has
done
it?


Gord




Sub TimeBombMakeReadOnly()
'''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
'''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

'''''''''''''''''''''''''''''''''''''''''''''''' ''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
'''''''''''''''''''''''''''''''''''''''''''''''' ''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub



Thanks again.



In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Colin

See Chip Pearson's site for creating a Time Bombed workbook.

http://www.cpearson.com/excel/workbooktimebomb.aspx


Gord Dibben MS Excel MVP

On Fri, 30 Nov 2007 01:52:58 +0000, Colin Hayes


wrote:


Hi

I need to have an excel file 'expire' 3 months after first installation.
Is it possible to build something into the program so that it will read
the date on first use and stop functioning after a set time , perhaps
with a popup too?

Any help appreciated.


Thanks



  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default How to time-limit an Excel file installation

Colin

Scroll down to the bottom of the page at Chip's site and he provides
Workbook_Open code to start the macro.

As far as a message goes, I guess you could add that here.

If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then


MsgBox "This workbook will now become read-only"

ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If


Why wait until tomorrow....change your system date.


Gord

On Sat, 1 Dec 2007 02:19:24 +0000, Colin Hayes wrote:



Hi Gord

OK Thanks for your help. I've inserted the module into my wb with this
as the code :


Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 1

Sub TimeBombMakeReadOnly()
''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

''''''''''''''''''''''''''''''''''''''''''''''''' '''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
''''''''''''''''''''''''''''''''''''''''''''''''' '''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub


i hope this is how it's meant to be. I haven't changed anything ,
although I made it one day so that I can see if it works by tomorrow.

I have a small question :

I really need this routine to start counting down as soon as the wb is
opened for the first time , on any machine. Does the macro have to be
run to set it working on each machine? If so , it sort of defeats the
object...!

Also , could you suggest some code to bring up a message box to show the
wb has expired?

Thanks

Colin




In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
See in-line responses..............

On Fri, 30 Nov 2007 13:35:38 +0000, Colin Hayes
wrote:


Hi

OK Thanks. I thought I'd try the one below.

I have a couple of questions though , if you could advise ;

The workbook it's protecting is called 'Receipts' - do I need to put
this anywhere in the code?


No. Thisworkbook is the workbook you are running the Sub on.

If I use this on more than one wb , do I need to change the name of the
file it stores , so as not to overwrite it.


No changes necessary as far as I can tell.....Thisworkbook refers to whatever
workbook the code is in.

I assume the file it is
storing is 'Expiration date'. It's not clear to me where it stores the
file....


Expiration Date is a named range which holds the date to expire. The code
creates this named range.

The line...........Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 90 must be

placed above the line..........Sub TimeBombMakeReadOnly()

Also , I'm not sure where I should be placing the code in the workbook.
Under the tab at the bottom , or under the Excel symbol at top-left of
the sheet...?


Alt + F11 to open VB Editor

CTRL + r to open Project Explorer if not visible.

Right-click on your workbook and InsertModule.

Paste code into that module with the edits above.

Save the workbook then run the macro which sets the time to expire as 90 days
from when you run the macro.

Have you downloaded the sample workbook from Chip's site to see how he has
done
it?


Gord




Sub TimeBombMakeReadOnly()
''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

''''''''''''''''''''''''''''''''''''''''''''''' '''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
''''''''''''''''''''''''''''''''''''''''''''''' '''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub



Thanks again.



In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Colin

See Chip Pearson's site for creating a Time Bombed workbook.

http://www.cpearson.com/excel/workbooktimebomb.aspx


Gord Dibben MS Excel MVP

On Fri, 30 Nov 2007 01:52:58 +0000, Colin Hayes


wrote:


Hi

I need to have an excel file 'expire' 3 months after first installation.
Is it possible to build something into the program so that it will read
the date on first use and stop functioning after a set time , perhaps
with a popup too?

Any help appreciated.


Thanks



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default How to time-limit an Excel file installation

On second thought, place your msgbox after the readonly save has taken place if
you feel you need a message.

ThisWorkbook.ChangeFileAccess xlReadOnly
End If
MsgBox "This workbook has become readonly"
End Sub

Make sure you read all of Chip's page including the caveats about security
weaknesses in Excel and how to make sure that users will enable macros when they
open the workbook.


Gord

On Fri, 30 Nov 2007 21:31:15 -0800, Gord Dibben <gorddibbATshawDOTca wrote:

Colin

Scroll down to the bottom of the page at Chip's site and he provides
Workbook_Open code to start the macro.

As far as a message goes, I guess you could add that here.

If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then


MsgBox "This workbook will now become read-only"

ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If


Why wait until tomorrow....change your system date.


Gord

On Sat, 1 Dec 2007 02:19:24 +0000, Colin Hayes wrote:



Hi Gord

OK Thanks for your help. I've inserted the module into my wb with this
as the code :


Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 1

Sub TimeBombMakeReadOnly()
'''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
'''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

'''''''''''''''''''''''''''''''''''''''''''''''' ''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
'''''''''''''''''''''''''''''''''''''''''''''''' ''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub


i hope this is how it's meant to be. I haven't changed anything ,
although I made it one day so that I can see if it works by tomorrow.

I have a small question :

I really need this routine to start counting down as soon as the wb is
opened for the first time , on any machine. Does the macro have to be
run to set it working on each machine? If so , it sort of defeats the
object...!

Also , could you suggest some code to bring up a message box to show the
wb has expired?

Thanks

Colin




In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
See in-line responses..............

On Fri, 30 Nov 2007 13:35:38 +0000, Colin Hayes
wrote:


Hi

OK Thanks. I thought I'd try the one below.

I have a couple of questions though , if you could advise ;

The workbook it's protecting is called 'Receipts' - do I need to put
this anywhere in the code?

No. Thisworkbook is the workbook you are running the Sub on.

If I use this on more than one wb , do I need to change the name of the
file it stores , so as not to overwrite it.

No changes necessary as far as I can tell.....Thisworkbook refers to whatever
workbook the code is in.

I assume the file it is
storing is 'Expiration date'. It's not clear to me where it stores the
file....

Expiration Date is a named range which holds the date to expire. The code
creates this named range.

The line...........Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 90 must be

placed above the line..........Sub TimeBombMakeReadOnly()

Also , I'm not sure where I should be placing the code in the workbook.
Under the tab at the bottom , or under the Excel symbol at top-left of
the sheet...?

Alt + F11 to open VB Editor

CTRL + r to open Project Explorer if not visible.

Right-click on your workbook and InsertModule.

Paste code into that module with the edits above.

Save the workbook then run the macro which sets the time to expire as 90 days
from when you run the macro.

Have you downloaded the sample workbook from Chip's site to see how he has
done
it?


Gord




Sub TimeBombMakeReadOnly()
'''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
'''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

'''''''''''''''''''''''''''''''''''''''''''''' ''''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
'''''''''''''''''''''''''''''''''''''''''''''' ''''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub



Thanks again.



In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Colin

See Chip Pearson's site for creating a Time Bombed workbook.

http://www.cpearson.com/excel/workbooktimebomb.aspx


Gord Dibben MS Excel MVP

On Fri, 30 Nov 2007 01:52:58 +0000, Colin Hayes

wrote:


Hi

I need to have an excel file 'expire' 3 months after first installation.
Is it possible to build something into the program so that it will read
the date on first use and stop functioning after a set time , perhaps
with a popup too?

Any help appreciated.


Thanks



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default How to time-limit an Excel file installation


Hi Gord

OK Thanks for that.

Is the 'Workbook_Open event procedure in the ThisWorkbook code module'
under the first tab on the worksheet , or under the Excel symbol top
left of the screen? I always confuse those. I'll put the code to run the
macro there.

Also , if I have the code in several different workbooks , will the
routine not over-write it's stored values , or is each record kept
separately for each wb when the code is in place?

Thanks again Gord



In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
On second thought, place your msgbox after the readonly save has taken place if
you feel you need a message.

ThisWorkbook.ChangeFileAccess xlReadOnly
End If
MsgBox "This workbook has become readonly"
End Sub

Make sure you read all of Chip's page including the caveats about security
weaknesses in Excel and how to make sure that users will enable macros when
they
open the workbook.


Gord

On Fri, 30 Nov 2007 21:31:15 -0800, Gord Dibben <gorddibbATshawDOTca wrote:

Colin

Scroll down to the bottom of the page at Chip's site and he provides
Workbook_Open code to start the macro.

As far as a message goes, I guess you could add that here.

If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then


MsgBox "This workbook will now become read-only"

ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If


Why wait until tomorrow....change your system date.


Gord

On Sat, 1 Dec 2007 02:19:24 +0000, Colin Hayes

wrote:



Hi Gord

OK Thanks for your help. I've inserted the module into my wb with this
as the code :


Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 1

Sub TimeBombMakeReadOnly()
''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

''''''''''''''''''''''''''''''''''''''''''''''' '''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
''''''''''''''''''''''''''''''''''''''''''''''' '''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub


i hope this is how it's meant to be. I haven't changed anything ,
although I made it one day so that I can see if it works by tomorrow.

I have a small question :

I really need this routine to start counting down as soon as the wb is
opened for the first time , on any machine. Does the macro have to be
run to set it working on each machine? If so , it sort of defeats the
object...!

Also , could you suggest some code to bring up a message box to show the
wb has expired?

Thanks

Colin




In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
See in-line responses..............

On Fri, 30 Nov 2007 13:35:38 +0000, Colin Hayes


wrote:


Hi

OK Thanks. I thought I'd try the one below.

I have a couple of questions though , if you could advise ;

The workbook it's protecting is called 'Receipts' - do I need to put
this anywhere in the code?

No. Thisworkbook is the workbook you are running the Sub on.

If I use this on more than one wb , do I need to change the name of the
file it stores , so as not to overwrite it.

No changes necessary as far as I can tell.....Thisworkbook refers to whatever
workbook the code is in.

I assume the file it is
storing is 'Expiration date'. It's not clear to me where it stores the
file....

Expiration Date is a named range which holds the date to expire. The code
creates this named range.

The line...........Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 90 must

be

placed above the line..........Sub TimeBombMakeReadOnly()

Also , I'm not sure where I should be placing the code in the workbook.
Under the tab at the bottom , or under the Excel symbol at top-left of
the sheet...?

Alt + F11 to open VB Editor

CTRL + r to open Project Explorer if not visible.

Right-click on your workbook and InsertModule.

Paste code into that module with the edits above.

Save the workbook then run the macro which sets the time to expire as 90

days
from when you run the macro.

Have you downloaded the sample workbook from Chip's site to see how he has
done
it?


Gord




Sub TimeBombMakeReadOnly()
''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

''''''''''''''''''''''''''''''''''''''''''''' '''''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
''''''''''''''''''''''''''''''''''''''''''''' '''''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub



Thanks again.



In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Colin

See Chip Pearson's site for creating a Time Bombed workbook.

http://www.cpearson.com/excel/workbooktimebomb.aspx


Gord Dibben MS Excel MVP

On Fri, 30 Nov 2007 01:52:58 +0000, Colin Hayes

wrote:


Hi

I need to have an excel file 'expire' 3 months after first installation.
Is it possible to build something into the program so that it will read
the date on first use and stop functioning after a set time , perhaps
with a popup too?

Any help appreciated.


Thanks




  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default How to time-limit an Excel file installation

Thisworkbook module is accessed under the Excel Icon left of "File" on the Menu
Bar after Right-click and "View Code".

On third thought, the msgbox should p[robably be wrapped inside the "If"
statement

ThisWorkbook.ChangeFileAccess xlReadOnly
MsgBox "This workbook has become readonly"
End If
End Sub

The stored value is in each workbook and is not common to all.

The stored value does not get overwritten after the first opening of the
workbook.

The name "Expiration Date" holding the start date is created and if it exists,
it is not re-created.

Keep reading Chip's instructions to get an idea of how all this works.


Gord

On Sat, 1 Dec 2007 14:08:33 +0000, Colin Hayes wrote:


Hi Gord

OK Thanks for that.

Is the 'Workbook_Open event procedure in the ThisWorkbook code module'
under the first tab on the worksheet , or under the Excel symbol top
left of the screen? I always confuse those. I'll put the code to run the
macro there.

Also , if I have the code in several different workbooks , will the
routine not over-write it's stored values , or is each record kept
separately for each wb when the code is in place?

Thanks again Gord



In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
On second thought, place your msgbox after the readonly save has taken place if
you feel you need a message.

ThisWorkbook.ChangeFileAccess xlReadOnly
End If
MsgBox "This workbook has become readonly"
End Sub

Make sure you read all of Chip's page including the caveats about security
weaknesses in Excel and how to make sure that users will enable macros when
they
open the workbook.


Gord

On Fri, 30 Nov 2007 21:31:15 -0800, Gord Dibben <gorddibbATshawDOTca wrote:

Colin

Scroll down to the bottom of the page at Chip's site and he provides
Workbook_Open code to start the macro.

As far as a message goes, I guess you could add that here.

If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then

MsgBox "This workbook will now become read-only"

ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

Why wait until tomorrow....change your system date.


Gord

On Sat, 1 Dec 2007 02:19:24 +0000, Colin Hayes

wrote:



Hi Gord

OK Thanks for your help. I've inserted the module into my wb with this
as the code :


Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 1

Sub TimeBombMakeReadOnly()
'''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
'''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

'''''''''''''''''''''''''''''''''''''''''''''' ''''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
'''''''''''''''''''''''''''''''''''''''''''''' ''''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub


i hope this is how it's meant to be. I haven't changed anything ,
although I made it one day so that I can see if it works by tomorrow.

I have a small question :

I really need this routine to start counting down as soon as the wb is
opened for the first time , on any machine. Does the macro have to be
run to set it working on each machine? If so , it sort of defeats the
object...!

Also , could you suggest some code to bring up a message box to show the
wb has expired?

Thanks

Colin




In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
See in-line responses..............

On Fri, 30 Nov 2007 13:35:38 +0000, Colin Hayes


wrote:


Hi

OK Thanks. I thought I'd try the one below.

I have a couple of questions though , if you could advise ;

The workbook it's protecting is called 'Receipts' - do I need to put
this anywhere in the code?

No. Thisworkbook is the workbook you are running the Sub on.

If I use this on more than one wb , do I need to change the name of the
file it stores , so as not to overwrite it.

No changes necessary as far as I can tell.....Thisworkbook refers to whatever
workbook the code is in.

I assume the file it is
storing is 'Expiration date'. It's not clear to me where it stores the
file....

Expiration Date is a named range which holds the date to expire. The code
creates this named range.

The line...........Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 90 must

be

placed above the line..........Sub TimeBombMakeReadOnly()

Also , I'm not sure where I should be placing the code in the workbook.
Under the tab at the bottom , or under the Excel symbol at top-left of
the sheet...?

Alt + F11 to open VB Editor

CTRL + r to open Project Explorer if not visible.

Right-click on your workbook and InsertModule.

Paste code into that module with the edits above.

Save the workbook then run the macro which sets the time to expire as 90

days
from when you run the macro.

Have you downloaded the sample workbook from Chip's site to see how he has
done
it?


Gord




Sub TimeBombMakeReadOnly()
'''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
'''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

'''''''''''''''''''''''''''''''''''''''''''' ''''''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
'''''''''''''''''''''''''''''''''''''''''''' ''''''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub



Thanks again.



In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Colin

See Chip Pearson's site for creating a Time Bombed workbook.

http://www.cpearson.com/excel/workbooktimebomb.aspx


Gord Dibben MS Excel MVP

On Fri, 30 Nov 2007 01:52:58 +0000, Colin Hayes

wrote:


Hi

I need to have an excel file 'expire' 3 months after first installation.
Is it possible to build something into the program so that it will read
the date on first use and stop functioning after a set time , perhaps
with a popup too?

Any help appreciated.


Thanks






  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default How to time-limit an Excel file installation



Hi Gord

OK Thanks for that. I've put it all in place and all seems well.

I do note from the article on cpearson.com that he says :

'This procedure, TimeBombWithDefinedName, uses a hidden defined name to
store the expiration date. The first time the workbook is opened, that
defined name will not exist and will be created by the code. **(Be sure
that you delete this name when you are done with your own development
work on the workbook.)'**

I'm not clear as to how I would go about deleting the hidden defined
name , or where I would find it.

Or should I just replace all references to 'Expiration Date' with some
other term and let it start again?

I assume also that if I were to lock myself out during development , I
could re-open the wb by disabling macros in excel. Would that work?


Thanks Gord for your help.





In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Thisworkbook module is accessed under the Excel Icon left of "File" on the Menu
Bar after Right-click and "View Code".

On third thought, the msgbox should p[robably be wrapped inside the "If"
statement

ThisWorkbook.ChangeFileAccess xlReadOnly
MsgBox "This workbook has become readonly"
End If
End Sub

The stored value is in each workbook and is not common to all.

The stored value does not get overwritten after the first opening of the
workbook.

The name "Expiration Date" holding the start date is created and if it exists,
it is not re-created.

Keep reading Chip's instructions to get an idea of how all this works.


Gord

On Sat, 1 Dec 2007 14:08:33 +0000, Colin Hayes
wrote:


Hi Gord

OK Thanks for that.

Is the 'Workbook_Open event procedure in the ThisWorkbook code module'
under the first tab on the worksheet , or under the Excel symbol top
left of the screen? I always confuse those. I'll put the code to run the
macro there.

Also , if I have the code in several different workbooks , will the
routine not over-write it's stored values , or is each record kept
separately for each wb when the code is in place?

Thanks again Gord



In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
On second thought, place your msgbox after the readonly save has taken place

if
you feel you need a message.

ThisWorkbook.ChangeFileAccess xlReadOnly
End If
MsgBox "This workbook has become readonly"
End Sub

Make sure you read all of Chip's page including the caveats about security
weaknesses in Excel and how to make sure that users will enable macros when
they
open the workbook.


Gord

On Fri, 30 Nov 2007 21:31:15 -0800, Gord Dibben <gorddibbATshawDOTca

wrote:

Colin

Scroll down to the bottom of the page at Chip's site and he provides
Workbook_Open code to start the macro.

As far as a message goes, I guess you could add that here.

If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then

MsgBox "This workbook will now become read-only"

ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

Why wait until tomorrow....change your system date.


Gord

On Sat, 1 Dec 2007 02:19:24 +0000, Colin Hayes


wrote:



Hi Gord

OK Thanks for your help. I've inserted the module into my wb with this
as the code :


Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 1

Sub TimeBombMakeReadOnly()
''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

''''''''''''''''''''''''''''''''''''''''''''' '''''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
''''''''''''''''''''''''''''''''''''''''''''' '''''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub


i hope this is how it's meant to be. I haven't changed anything ,
although I made it one day so that I can see if it works by tomorrow.

I have a small question :

I really need this routine to start counting down as soon as the wb is
opened for the first time , on any machine. Does the macro have to be
run to set it working on each machine? If so , it sort of defeats the
object...!

Also , could you suggest some code to bring up a message box to show the
wb has expired?

Thanks

Colin




In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
See in-line responses..............

On Fri, 30 Nov 2007 13:35:38 +0000, Colin Hayes

wrote:


Hi

OK Thanks. I thought I'd try the one below.

I have a couple of questions though , if you could advise ;

The workbook it's protecting is called 'Receipts' - do I need to put
this anywhere in the code?

No. Thisworkbook is the workbook you are running the Sub on.

If I use this on more than one wb , do I need to change the name of the
file it stores , so as not to overwrite it.

No changes necessary as far as I can tell.....Thisworkbook refers to

whatever
workbook the code is in.

I assume the file it is
storing is 'Expiration date'. It's not clear to me where it stores the
file....

Expiration Date is a named range which holds the date to expire. The code
creates this named range.

The line...........Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 90

must
be

placed above the line..........Sub TimeBombMakeReadOnly()

Also , I'm not sure where I should be placing the code in the workbook.
Under the tab at the bottom , or under the Excel symbol at top-left of
the sheet...?

Alt + F11 to open VB Editor

CTRL + r to open Project Explorer if not visible.

Right-click on your workbook and InsertModule.

Paste code into that module with the edits above.

Save the workbook then run the macro which sets the time to expire as 90
days
from when you run the macro.

Have you downloaded the sample workbook from Chip's site to see how he

has
done
it?


Gord




Sub TimeBombMakeReadOnly()
''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

''''''''''''''''''''''''''''''''''''''''''' '''''''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
''''''''''''''''''''''''''''''''''''''''''' '''''''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub



Thanks again.



In article , Gord

Dibben
<gorddibbATshawDOTca@?.? writes
Colin

See Chip Pearson's site for creating a Time Bombed workbook.

http://www.cpearson.com/excel/workbooktimebomb.aspx


Gord Dibben MS Excel MVP

On Fri, 30 Nov 2007 01:52:58 +0000, Colin Hayes

wrote:


Hi

I need to have an excel file 'expire' 3 months after first installation.
Is it possible to build something into the program so that it will read
the date on first use and stop functioning after a set time , perhaps
with a popup too?

Any help appreciated.


Thanks





  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default How to time-limit an Excel file installation

To get rid of the hidden name "Expiration Date" you could run this macro.

Sub foo()
For Each Name In ThisWorkbook.Names
Name.Visible = True
Next
End Sub

Now go to InsertNameDefine and delete the name which you will see refers to
the expiry date.

Save the workbook which is now ready for the name to be re-created when you
next open it.

If user is sophisticated enough he will be able to run a similar macro and
change the date from 90 days to 9000 days but if he is that savvy then he will
have defeated your original code anyway.

If by "locked out" you mean you have already made the workbook read-only,
disabling macros will not change the read-only property.

Just save as a copy of the original after deleting the name then disable macros
if you want to do more editing of code. You may have to do this several times
before you final copy is ready.

When ready for distribution make sure you have deleted the name and protected
the project under VBA Project Properties.


Gord


On Sat, 1 Dec 2007 22:47:18 +0000, Colin Hayes wrote:



Hi Gord

OK Thanks for that. I've put it all in place and all seems well.

I do note from the article on cpearson.com that he says :

'This procedure, TimeBombWithDefinedName, uses a hidden defined name to
store the expiration date. The first time the workbook is opened, that
defined name will not exist and will be created by the code. **(Be sure
that you delete this name when you are done with your own development
work on the workbook.)'**

I'm not clear as to how I would go about deleting the hidden defined
name , or where I would find it.

Or should I just replace all references to 'Expiration Date' with some
other term and let it start again?

I assume also that if I were to lock myself out during development , I
could re-open the wb by disabling macros in excel. Would that work?


Thanks Gord for your help.





In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
Thisworkbook module is accessed under the Excel Icon left of "File" on the Menu
Bar after Right-click and "View Code".

On third thought, the msgbox should p[robably be wrapped inside the "If"
statement

ThisWorkbook.ChangeFileAccess xlReadOnly
MsgBox "This workbook has become readonly"
End If
End Sub

The stored value is in each workbook and is not common to all.

The stored value does not get overwritten after the first opening of the
workbook.

The name "Expiration Date" holding the start date is created and if it exists,
it is not re-created.

Keep reading Chip's instructions to get an idea of how all this works.


Gord

On Sat, 1 Dec 2007 14:08:33 +0000, Colin Hayes
wrote:


Hi Gord

OK Thanks for that.

Is the 'Workbook_Open event procedure in the ThisWorkbook code module'
under the first tab on the worksheet , or under the Excel symbol top
left of the screen? I always confuse those. I'll put the code to run the
macro there.

Also , if I have the code in several different workbooks , will the
routine not over-write it's stored values , or is each record kept
separately for each wb when the code is in place?

Thanks again Gord



In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
On second thought, place your msgbox after the readonly save has taken place

if
you feel you need a message.

ThisWorkbook.ChangeFileAccess xlReadOnly
End If
MsgBox "This workbook has become readonly"
End Sub

Make sure you read all of Chip's page including the caveats about security
weaknesses in Excel and how to make sure that users will enable macros when
they
open the workbook.


Gord

On Fri, 30 Nov 2007 21:31:15 -0800, Gord Dibben <gorddibbATshawDOTca

wrote:

Colin

Scroll down to the bottom of the page at Chip's site and he provides
Workbook_Open code to start the macro.

As far as a message goes, I guess you could add that here.

If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then

MsgBox "This workbook will now become read-only"

ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

Why wait until tomorrow....change your system date.


Gord

On Sat, 1 Dec 2007 02:19:24 +0000, Colin Hayes


wrote:



Hi Gord

OK Thanks for your help. I've inserted the module into my wb with this
as the code :


Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 1

Sub TimeBombMakeReadOnly()
'''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
'''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

'''''''''''''''''''''''''''''''''''''''''''' ''''''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
'''''''''''''''''''''''''''''''''''''''''''' ''''''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub


i hope this is how it's meant to be. I haven't changed anything ,
although I made it one day so that I can see if it works by tomorrow.

I have a small question :

I really need this routine to start counting down as soon as the wb is
opened for the first time , on any machine. Does the macro have to be
run to set it working on each machine? If so , it sort of defeats the
object...!

Also , could you suggest some code to bring up a message box to show the
wb has expired?

Thanks

Colin




In article , Gord Dibben
<gorddibbATshawDOTca@?.? writes
See in-line responses..............

On Fri, 30 Nov 2007 13:35:38 +0000, Colin Hayes

wrote:


Hi

OK Thanks. I thought I'd try the one below.

I have a couple of questions though , if you could advise ;

The workbook it's protecting is called 'Receipts' - do I need to put
this anywhere in the code?

No. Thisworkbook is the workbook you are running the Sub on.

If I use this on more than one wb , do I need to change the name of the
file it stores , so as not to overwrite it.

No changes necessary as far as I can tell.....Thisworkbook refers to

whatever
workbook the code is in.

I assume the file it is
storing is 'Expiration date'. It's not clear to me where it stores the
file....

Expiration Date is a named range which holds the date to expire. The code
creates this named range.

The line...........Private Const C_NUM_DAYS_UNTIL_EXPIRATION = 90

must
be

placed above the line..........Sub TimeBombMakeReadOnly()

Also , I'm not sure where I should be placing the code in the workbook.
Under the tab at the bottom , or under the Excel symbol at top-left of
the sheet...?

Alt + F11 to open VB Editor

CTRL + r to open Project Explorer if not visible.

Right-click on your workbook and InsertModule.

Paste code into that module with the edits above.

Save the workbook then run the macro which sets the time to expire as 90
days
from when you run the macro.

Have you downloaded the sample workbook from Chip's site to see how he

has
done
it?


Gord




Sub TimeBombMakeReadOnly()
'''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''
' TimeBombMakeReadOnly
' This procedure uses a defined name to store the expiration
' date and if the workbook has expired, makes the workbook
' read-only.
'''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''

Dim ExpirationDate As String
Dim NameExists As Boolean

On Error Resume Next
ExpirationDate = Mid(ThisWorkbook.Names("ExpirationDate").Value, 2)
If Err.Number < 0 Then
'''''''''''''''''''''''''''''''''''''''''''
' Name doesn't exist. Create it.
'''''''''''''''''''''''''''''''''''''''''''
ExpirationDate = CStr(DateSerial(Year(Now), _
Month(Now), Day(Now) + C_NUM_DAYS_UNTIL_EXPIRATION))
ThisWorkbook.Names.Add Name:="ExpirationDate", _
RefersTo:=Format(ExpirationDate, "short date"), _
Visible:=False
NameExists = False
Else
NameExists = True
End If

'''''''''''''''''''''''''''''''''''''''''' ''''''''''''
' If the today is past the expiration date, make the
' workbook read only. We need to Save the workbook
' to keep the newly created name intact.
'''''''''''''''''''''''''''''''''''''''''' ''''''''''''
If CDate(Now) = CDate(ExpirationDate) Then
If NameExists = False Then
ThisWorkbook.Save
End If
ThisWorkbook.ChangeFileAccess xlReadOnly
End If

End Sub



Thanks again.



In article , Gord

Dibben
<gorddibbATshawDOTca@?.? writes
Colin

See Chip Pearson's site for creating a Time Bombed workbook.

http://www.cpearson.com/excel/workbooktimebomb.aspx


Gord Dibben MS Excel MVP

On Fri, 30 Nov 2007 01:52:58 +0000, Colin Hayes

wrote:


Hi

I need to have an excel file 'expire' 3 months after first installation.
Is it possible to build something into the program so that it will read
the date on first use and stop functioning after a set time , perhaps
with a popup too?

Any help appreciated.


Thanks





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Installation Error: File not Found jwill_03 Excel Discussion (Misc queries) 0 November 6th 07 09:59 PM
Installation Problem - Missing File caroline Excel Discussion (Misc queries) 0 July 26th 07 03:48 PM
Installation error, file not found Home Girl Excel Discussion (Misc queries) 1 June 30th 07 12:54 PM
excel won't open, keeps saying installation file missing? Brian Mills Excel Discussion (Misc queries) 1 April 10th 06 04:52 PM
A required installation file E2561412.CAB could not be found AC Excel Discussion (Misc queries) 0 March 12th 06 10:49 PM


All times are GMT +1. The time now is 09:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"