Page 1 of 1
[Solved] Macro to delete sheet
Posted: Sun Jul 08, 2018 3:48 pm
by Nocton
I have a macro to delete a sheet ('Working') no longer needed:
Code: Select all
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "aTableName"
args3(0).Value = "Working"
dispatcher.executeDispatch(document, ".uno:Show", "", 0, args3())
dispatcher.executeDispatch(document, ".uno:Remove", "", 0, Array())
It all works OK. But when I run it I always get the message: "Are you sure you want to delete the selected sheets?". How can I avoid seeing this message?
Re: Macro to delete sheet
Posted: Sun Jul 08, 2018 4:22 pm
by FJCC
Use the API(Application Programming Interface) instead of recorded commands.
Code: Select all
oSheets = ThisComponent.getSheets()
oSheets.removeByName("Working")
Re: Macro to delete sheet
Posted: Sun Jul 08, 2018 4:33 pm
by Villeroy
The MRI extension can record valid API code.
Re: [Solved] Macro to delete sheet
Posted: Sun Jul 08, 2018 5:07 pm
by Nocton
How can I do that, Villeroy, as I see nothing about recording on the Macros menu.
Re: [Solved] Macro to delete sheet
Posted: Sun Jul 08, 2018 5:09 pm
by RoryOF
Complete MRI documentation is at
https://github.com/hanya/MRI/wiki
Re: [Solved] Macro to delete sheet
Posted: Sun Jul 08, 2018 6:16 pm
by Villeroy
To be more precise, it does not record your actions in the office UI. It records your double-clicks in the MRI window.
Starting from any spreadsheet window with more than one sheet
menu:Tools>AddOns>MRI (inspects the current document)
Make the MRI window as tall as possible
Hit Ctrl+H to open the code sub-window
Double-click pseudo-property "Sheets" or method "getSheets"
Double-click method "getByName" and select a name
Click the < button to go back to the sheets collection
Double-click method removeByName and enter the sheet name
The sheet is removed and you have all the code in the code sub-window.
menu:Tools>Code>[some language] and you see the same code in another language
Re: [Solved] Macro to delete sheet
Posted: Sun Jul 08, 2018 8:27 pm
by Nocton
Many thanks, Villeroy, that is really helpful.