Consulting

Results 1 to 2 of 2

Thread: Lock record creation in Excel

  1. #1
    VBAX Newbie
    Joined
    Sep 2007
    Posts
    1
    Location

    Lock record creation in Excel

    I'm new at Vb so please be gentle...

    I need to create a date and time "serial Number" in Excel that will not change when the document is opened a second time. If I use the =NOW() function, the date will be auto entered but will change when I reopen the doc later. How do I lock this so once it is entered, it will remain as a record of when the doc was saved?

    Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    With Worksheets("Sheet1").Range("A1")
    .Value = Now
    .NumberFormat = "dd-mmm-yyyy hh:mm:ss"
    End With
    End Sub

    Private Sub Workbook_Open()

    End Sub
    [/vba]

    This is workbook event code.
    To input this code, right click on the Excel icon on the worksheet
    (or next to the File menu if you maximise your workbooks),
    select View Code from the menu, and paste the code
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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