Hello @SmileAway,
you could set a Listener to cell B3, then you receive a callback when the cell is modified:
REM ***** ModifyListener *****
Global oModifyListener As Object
Global oCell As Object
Sub SetModifyListener()
REM call this method once to set the ModifyListener.
REM to destroy the listener, call RemoveModifyListener().
REM ( change "B3" to the cell which should trigger the modified() callback if modified )
Dim oSheet As Object
Const strCellAddress$ = "B3" REM Your Cell Address here.
oModifyListener = createUnoListener("CellModify_","com.sun.star.util.XModifyListener")
oSheet = ThisComponent.CurrentController.ActiveSheet
oCell = oSheet.getCellRangebyName( strCellAddress )
oCell.addModifyListener( oModifyListener )
End Sub
Sub RemoveModifyListener()
If Not IsNull( oCell ) Then oCell.removeModifyListener( oModifyListener )
End Sub
Sub CellModify_modified( oEvent )
oEvent.Source.getSpreadsheet.setName( oEvent.Source.getString )
End Sub
Sub CellModify_disposing( oEvent )
End Sub
REM ***** End *****
EDIT 1:
i made a few adjustments in the code above:
Global oModifyListener As Object
Global oCell As Object
and:
Sub RemoveModifyListener()
If Not IsNull( oCell ) Then oCell.removeModifyListener( oModifyListener )
End Sub
EDIT 2:
To set the ModifyListener automatically when your document opens:
1) select the main menu "Tools:Customize..."
2) in the dialog that pops up, select the tab "Events"
3) in the Events listbox, select the item "Open Document" ,
4) click the "Macro..." button,
5) in the Macro Selector dialog that pops up, locate your macro "SetModifyListener()" and click OK,
6) back in the Events listbox, select the item "Document is going to be closed",
7) click the "Macro..." button again,
8) in the Macro Selector dialog that pops up, locate your macro "RemoveModifyListener()" and click OK.