PDA

View Full Version : limited times or dates usage



jinvictor
06-20-2006, 07:07 AM
i got 2 vbas to do the job for me.

first one control the times they used the workbook:


Private Sub Workbook_Open()
Dim incRange As Range
Set incRange = Range("Increment")

Sheets("hidden").Visible = xlVeryHidden
incRange = incRange + 1
Me.Save
If incRange > 10 Then
Application.DisplayAlerts = False
MsgBox "over the use limit, contact owner"
Me.Close
End If

End Sub

the second one controls how many days they can use:


Private Sub Workbook_Open()
Dim StartDate As Date

StartDate = "19/06/06" 'Date delivered to customer
If Date - StartDate > 14 Then ' Two week trial period
Application.DisplayAlerts = False
MsgBox "Trial period expired, contact owner"
Me.Close
End If

End Sub

how can i combine these 2 together, so i can use both of them to control the workbook?

lucas
06-20-2006, 07:16 AM
Please see this kb entry by John:
http://vbaexpress.com/kb/getarticle.php?kb_id=475

jinvictor
06-20-2006, 07:22 AM
but what shall i do if i want use these 2 vba together, because both of them work perfectly individual.


Please see this kb entry by John:
http://vbaexpress.com/kb/getarticle.php?kb_id=475

lucas
06-20-2006, 07:30 AM
If you look at the kb entry closely you will see that it performs both of the functions you have listed in post 1.......John has been working on this for some time and this is the end result of much research. Please take a closer look.

mdmackillop
06-20-2006, 12:56 PM
Hi JinVictor,
Please use the VBA tags on your code. Select the code text and click the VBA button.

mdmackillop
06-20-2006, 01:05 PM
Private Sub Workbook_Open()
Dim incRange As Range
Dim StartDate As Date

Set incRange = Range("Increment")
StartDate = "19/06/06" 'Date delivered to customer

Sheets("hidden").Visible = xlVeryHidden
incRange = incRange + 1
Me.Save
If incRange > 10 Or Date - StartDate > 14 Then
Application.DisplayAlerts = False
MsgBox "over the use limit, contact owner"
Me.Close
End If

End Sub


If the user does not enable macros, however, the code will not run and the workbook will remain open.

jinvictor
06-20-2006, 07:19 PM
thank you for all your time, it works perfectly. thanx again!