Hi!
I have a spreadsheet with 10 sheets. I’m trying to figure out how to rename the sheets to whatever I put in a specific cell such as P3. Sheet number 1 works with the code below, but I can’t seem to get it working for the other sheets.
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 "P3" to the cell which should trigger the modified() callback if modified )
Dim oSheet As Object
Const strCellAddress$ = "P3" 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 *****
(Code formatted as code by @Lupp )