View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Change control methods

1) It seems you just want to detect a change. SO you could use
worksheet_change event to set a global flag, and test that in BeforeClose
event.

This code would go in Thisworkbook

Public fChange As Boolean


Private Sub Workbook_BeforeClose(Cancel As Boolean)
If fChange Then
MsgBox "File changed, save under another name"
Cancel = True
End If
End Sub

and then

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
On Error GoTo sub_exit
If Not Intersect(Target, Range("A1")) Is Nothing Then
With Target
ThisWorkbook.fChange = True
End With
End If
sub_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Geoff C" <Geoff wrote in message
...
Can someone help me with some related but slightly different problems?

1) Is there a function that will detect whether or not a cell has been
changed since a spreadsheet was opened? If so I can use this to prompt a
user to increment a version number in the file, which in turn will prompt
them to save the file to a different file name.

2) That's my simplest hope. If not, is there a method of automatically
incrementing a version number when a file opens? This would also mean I
would have to somehow force the user to save the file to a different file
name, since it would not be immediately obvious that it has happened (if

you
see what I mean). Can this be done?