At the moment I have to press “sheet” >”sheet tab color”, and chose the color, is it possible using a macro to change a sheet tab color to a designated color instantly?
ThisComponent.getSheets().getByIndex(1).TabColor = 255
will change the color of the tab of the second sheet to blue
would it be possible to make it change the tab color for the active sheet, instead of the second sheet?
Why not? ThisComponent.getCurrentController().getActiveSheet().TabColor = 255*255
will change the color of the tab of the active sheet to green
“would it be possible to make it change the tab color for the active sheet, instead of the second sheet?”
Please install one of the excellent object Inspection tools: XrayTool or MRI.
Then you will able to list the properties and methods of the API related programming objects. And please study the API functions - if you want control the LO by macros efficiently.
oSheet = ThisComponent.getCurrentController.getActiveSheet
oSheet.TabColor = 255
for some reason i get error "basic syntax error, expected: sub https://i.imgur.com/0JUmYMi.png when I run it
It is depend on that fact: how and where you launch the macro from.
Try my sample file: you can launch the macro on a Sheet by a pushbutton.
I attached the sample file at my Answer above.
@michaely: May it be that you never before created a “macro” in Basic?
If you now created a new module (Module1 by default), its content (below a commenting line) should look like
Sub Main
End Sub
This is what a minimal subroutine not doing anything must have like a frame. You may insert one of the statements suggested above between the two quoted lines to get it work - and you may change the name Main
to something you like better.
Appending the statement(s) you want to be executed below or replacing the complete “frame” by it won’t work, and will cause an error of the reported kind.
If this was the reason of your issue: Consider basically if you need to use macros. If so, you need to study the basics.
Thanks folks! putting “End Sub” at the end fixed it
do you know how to change tab color of multiple tabs, instead of just the active tab? E.g. I’d like to change the tab color of tabs 1-22
Manually: select more than one sheets, and adjust the TAB color.
By macro: it is depend on if you want to colorize:
- all of the TABs
- the TABs of the selected sheets
- a specific list of the tabs.