Renaming sheet todays date

Hello, I have a calc file which is basically an inventory record. Periodically, I record inventory amounts, then I want to save the sheet (create sheet copy), rename it with today’s date, and protect that sheet, keeping the current sheet unprotected.

I am trying to create a macro to do this also. Am unable to rename a sheet with today’s date, when I do I get “=today()” which is what I enter. Did this in excel many years ago, so can’t recall exact steps or functions. Is there a better function, how do I format, also how do I make it so it always saves todays just behind the “master” sheet.

Thank you for your help.

It’s not very difficult:

Sub CopyAndProtect
Const MAIN_SHEET = "Main" ' Name of your "Input Form", your "master sheet"  '
Dim oSheets As Variant
Dim oSheet As Variant
Dim sName As String
	oSheets = ThisComponent.getSheets()
	If Not oSheets.hasByName(MAIN_SHEET) Then 
		MsgBox("No sheet named '" + MAIN_SHEET +"'!", MB_ICONSTOP, "Wrong spreadsheet")
		Exit Sub
	EndIf
	sName = Format(Now,"YYYY-MM-DD")
	If oSheets.hasByName(sName) Then 
		If MsgBox("The '" + sName +"' sheet already exists. Want to replace?",  _
			MB_YESNO + MB_ICONQUESTION, "Is it double?") = IDYES Then
				oSheets.removeByName(sName)
		Else 
			Exit Sub
		EndIf
	EndIf
	oSheets.copyByName(MAIN_SHEET, sName, 1)
	oSheet = oSheets.getByName(sName)
	oSheet.protect(sName) ' Password same as sheetname, change it as you want '
End Sub

Mumbling: Sheetname should always regard ordinary name syntax. Suggest format string Date_YYYY_MM_DD.

Mumbling: I’m tired of giving absolutely correct answers - they just take a ready-made solution and stop thinking … I will make small mistakes - correcting them they will learn something … probably …