Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Insert date in cell when first edit workbook - no change after

Hi,

I would like to have automatic date or time stamp in specific cell when user firstly edit workbook or sheet using excel template file. All found functions using workbook open or change, but I want to achieve not changing date after first edit of the workbook. Any help?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,182
Default Insert date in cell when first edit workbook - no change after

Hi,

I would like to have automatic date or time stamp in specific cell when user
firstly edit workbook or sheet using excel template file. All found functions
using workbook open or change, but I want to achieve not changing date after
first edit of the workbook. Any help?


Leave the cell empty and test for that when opened.

To test if any sheet in the file gets edited, you can place the date/time into
the cell using the Now() function via the Workbook_SheetChange event.

Use the Worksheet_Change event for testing if individual sheets get edited. You
could do this in the Workbook_SheetChange event as well.

You could also add the username of the person who did the editing; -so 1st edit
gets the date/time stamp + delimiter + username and subsequent edits get
delimiter + username appended to the existing 'Value'. You could also add the
date/time stamp to subsequent edits using a different delimiter so your code
knows which to use when!

I suggest using a named cell local to the sheet where the cell resides; -where
the cell is hidden (row above the data in a fixed column works best). This will
require referncing the sheet named range when reading/writing the cell, so
giving it local scope allows reusing the same name on sheets without conflict
since workbook events include a ref to the sheet. Worksheet events are ref'd
using the keyword 'Me'.

So...

In a standard module Declarations section:

Option Explicit

Public gwksProgData As Worksheet, grngEdit As Range
Public gsUser$, gbEdited As Boolean

Public Const gsRngEdit$ = "ptrEdit" '//local scope named range
Public Const gsDelimited$ = "|" '//list delimiter
Public Const gsDelimiter$ = ":" '//value pair delimiter


Sub InitGlobals()
' Initializes global variables at startup
Set gwksProgData = ThisWorkbook.Sheets("ProgData") '//stores project data
gsUser = Environ("username") '//current user
'initialize others as required
End Sub

Sub ShutdownCleanup()
' Releases runtime objects from memory
On Error Resume Next
Set gwksProgData = Nothing: Set grngEdit = Nothing
End Sub

Sub RecordEdit()
' Stores when/who edits this file
' Supports listing delimited value pairs
If Not gbEdited Then Exit Sub '//no edits

With grngEdit
If .Value = Empty Then
.Value = Now() '& gsDelimiter & gsUser
Else '//it's being edited again
' .Value = .Value & gsDelimited & Now() & gsDelimiter & gsUser
End If
End With
gbEdited = False '//reset flag
End Sub 'RecordEdit


In the ThisWorkbook code:

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call ShutdownCleanup
End Sub

Private Sub Workbook_Open()
Call InitGlobals
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
gbEdited = True
Set grngEdit = gwksProgData.Range(gsRngEdit): RecordEdit
End Sub


If also using this for tracking individual worksheets, in the worksheet code:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
gbEdited = True
Set grngEdit = Me.Range(gsRngEdit): RecordEdit
End Sub

...where project data/settings/lists etc. are stored on a hidden sheet named
"ProgData" and accessed by any code in the workbook. Individual sheets store in
hidden ranges or use local scope Defined Names.

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
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
opening a link in a workbook cell to edit?? MikeR-Oz New Users to Excel 1 September 21st 08 04:15 AM
how to insert the date in and make it change automatiquely cpl Excel Programming 3 November 18th 06 12:58 AM
Vlookup doesn't work until i edit(but not change) the lookup cell Confused Excel Worksheet Functions 4 November 8th 05 09:15 AM
Automatically Insert DATE, so that DATE will NOT change Cie Excel Worksheet Functions 4 April 4th 05 05:51 PM
Edit information in a cell and not change content shively5 Excel Programming 4 February 14th 04 07:06 PM


All times are GMT +1. The time now is 05:00 PM.

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

About Us

"It's about Microsoft Excel"