Make macro to name new sheets in calc

Hi, I am stuck working on a macro for my loan and credit card debit presentation. I have a learning disability and some dementia to aid in my problem-solving challenges and old knowledge of basic. I wish to display 6 to 10 accounts showing each month’s payments for each account. Accounts will have their own page. Using LibreOffice Calc 24 on windows 10 to make a data sheets with account information. A range of cells containing the account names will be the names for the following sheets made by my macro.
I downloaded a script from an AI, and it names my data sheet. It hangs up with a “basic runtime error object variable not set”, and does not create new sheets. I want it to create and name sheets for whatever is in my cell range. I have no idea what to do next so please help me.
My test data sheet has from a1 to a10 of 2 letter combinations for sheet names ab, cd, ef, etc… My macro looks like this:



sub NameSheetFromCellRange

dim osheet as object
dim oCellRange as object
dim I as integer
dim sSheetName as string

ThisComponent.getsSheets().getByIndex(0).getCellRangeByName(“a1:a10)

	for	i= 0  to oCellRange.getRows().getCount() - 1         ‘this line

		sSheetName = oCellRange.getCellByPosition(i,0).getString()

		if	ThisComponent.getsSheets().hasByName(sSheetName) then
			oSheet = ThisComponent.getSheets().getByIndex(i)
		else
			ThisComponent.getSheets().insertNewByName(sheetname, I)
		end if
	next i
end sub

I apologize for this repeat. My earlier attempts to log onto the site were unsuccessful. I’m catching up with things now.

Not an answer but you really should read this to help you use Markdown so your post are readable and consistent, This is the guide - How to use the Ask site? - #6 by erAck

sSheetName <> sheetname

1 Like

I checked the original, it is correct; I mistyped in this copy.

Please upload your ODF type sample file here.

ab
cd
ef
gh
ij
kl
mn
op
qr
st

Is that what you meant?

Is that an ODF type sample file?!
(ODF: Open Dofument Format file with “.ods”, “.odt”, “.odg”, “.odp” filename extension…)
Please prepare a .ods type sample file: remove the sensitive content from a copy of your file, and upload it here.

this is python:

def create_new_sheets(*_):
    doc = XSCRIPTCONTEXT.getDocument()
    sheets = doc.Sheets
    names = sheets[0]["A1:A10"].DataArray
    names = set( row[0] for row in names)
    for name in names.difference( sheets.ElementNames):
        sheets.insertNewByName(name, sheets.Count)