+ Reply to Thread
Results 1 to 6 of 6

WorkBook Expire

  1. #1
    Forum Contributor
    Join Date
    12-04-2006
    Posts
    201

    WorkBook Expire

    Hi,

    i need to set and expire date, that i can change every month through VBA. I want it to check for the expire date when the user opens the file, but it should still let the user open it, just not save it, with a msg box appearing warning the user. Has enyone got any ideas on how to achieve this,

    thanks

  2. #2
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Use the following event module
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    and test your dates ...
    HTH
    Carim


    Top Excel Links

  3. #3
    Forum Contributor
    Join Date
    12-04-2006
    Posts
    201
    Hi,

    I'm already using the Private Sub Workbook_BeforeClose(Cancel As Boolean) event module. I'm just not sure on the code to use??

    thanks

  4. #4
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Ok then ...
    Could you share your code with us, for a precise answer ...

  5. #5
    Forum Contributor
    Join Date
    12-04-2006
    Posts
    201
    Hi,

    I was trying to adapt the code below, but failed miserably...



    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim nm As Name, useDate As Date

    On Error Resume Next
    Set nm = ThisWorkbook.Names("FirstUse")
    If Err Or nm Is Nothing Then
    'this is first use, save the date
    Err.Clear
    ThisWorkbook.Names.Add _
    Name:="FirstUse", _
    Visible:=False, _
    RefersTo:=Date

    Else
    'check today vs. first use
    useDate = Right(nm.RefersTo, 5)
    'MsgBox useDate
    If DateDiff("d", useDate, Date) > 30 Then
    ThisWorkbook.Close
    End If
    End If

    End Sub

    thanks

  6. #6
    Forum Contributor
    Join Date
    12-04-2006
    Posts
    201
    Can anyone help with this????

    thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1