I have a Writer Template that has a custom toolbar that I created. If a user chooses to NOT have support for some functionality in his odt file (Monthly Expenses) then the template removes that code module from the odt file it creates. But there are still one or two icons for Monthly Expenses that are left on the custom toolbar that I want to also remove permanently from the odt file’s custom toolbar so that the user cannot click on them. (They would point to macros in the module that was removed.) As another solution, I could create a second custom toolbar specific to the Monthly Expenses module and completely delete it, if that’s possible.
I did find some BASIC macro code that will allow you to remove an icon from a toolbar, or even remove the toolbar itself, but this removal is not permanent.
Sub RemoveTBarItem()
Dim oLayoutManager, Tbar, TBarSettings As Object
oLayoutManager = ThisComponent.CurrentController.Frame.LayoutManager
TBar = oLayoutManager.getElement(“private:resource/toolbar/custom_toolbar_c6e”)
TBarSettings = TBar.getSettings(true)
TBarSettings.removeByIndex(1)
TBar.setSettings(TBarSettings)
Tbar.updateSettings()
End Sub
In the above Sub, you can even use TBar .dispose() to get rid of the toolbar. But as I say, if you then save the document then reopen it, the toolbar is still there as well as the icon you tried to remove.
What I want is the same result that you can get using Tools → Customize → Toolbars where you select the document on the right side, at the top (Scope), then select your custom toolbar below that (Target), after which you can easily click on any of the icons on the toolbar then click the left pointing arrow to remove it – permanently. You can also click on the little gear-like icon beside the name of the icon and it will give you the option to permanently remove the custom toolbar altogether.
I need the same ind of functionality through a macro that is run in the template so that the unwanted icons, or custom toolbar, is not in the odt file. Any help would be greatly appreciated.