Hello, I’m trying to do a simple task with a macro. In the first part (code below) I try to copy the active sheet, give it a new name and make the new one the active sheet. the second part works with cells and it’s not relevant as I recorded it and used that code.
The problem is that I can’t seem to be able to set the active sheet and outputs the next error message
BASIC runtime error.
Object variable not set.
I’m very new to writing macros and surely I’m doing something wrong.
sub copysheet
dim oDoc
dim oSheets
dim oController
dim oSheet as string
dim sheetName as string
dim oNewSheet
oDoc = thisComponent
oSheets = oDoc.getSheets()
sheetName = inputbox ("Name the new sheet:")
if oSheets.hasByName(sheetName) then
msgbox "Can't use that name! Try another one"
else
oSheet = thiscomponent.currentController.activeSheet.name
oSheets.copyByName(oSheet,sheetName, 0)
oNewSheet = thiscomponent.currentController
oNewSheet.setActiveSheet(sheetName) 'this line is where the error message appears
endif
end sub
Any advice will be appreciated.
Edit: Spelling.