can two different macros be integrated/combined with each other?

I’m trying to combine the two into one so both functions will be accomplished at once, any idea how I should combine the two?

Sub restoreTabColor
Dim oSheet As Variant
    For Each oSheet In ThisComponent.getSheets()
        oSheet.TabColor = -1
    Next oSheet
End Sub

Sub demo()
doc = ThisComponent
rgs = doc.createInstance("com.sun.star.sheet.SheetCellRanges")
Dim aRgA As New com.sun.star.table.CellRangeAddress
With aRgA
  .StartColumn = 2
  .EndColumn = 22
  .StartRow = 1
  .EndRow = 1298
  For j = 0 To 22
    .sheet = j
    rgs.addRangeAddress(aRgA, False)
  Next j
End With
rgs.clearContents(1023) REM To clear all content
End Sub

Don’t understand:

Sub Combined()
  Call restoreTabColor
  Call demo 
End Sub

doesn’t work for you?

Where’s the problem?
You can call one Subrotine from the other one (from inside a loop e.g.) or write a specialized routine first calling one Sub and then a different one…
But never hard-code sheet indices or complete range addresses. if not a very strange and special situation is forcing you to do so. Routines of the kind you posted are mostly better called for ThisComponent.CurrentSelection where the SheetCellRange(s) is (are) selected in one sheet, and the selection is expanded to additional sheets by Ctrl+ClickOnTab

I tried

Sub Combined()
Call restoreTabColor
Dim oSheet As Variant
    For Each oSheet In ThisComponent.getSheets()
        oSheet.TabColor = -1
    Next oSheet
End Sub
Call demo()
doc = ThisComponent
rgs = doc.createInstance("com.sun.star.sheet.SheetCellRanges")
Dim aRgA As New com.sun.star.table.CellRangeAddress
With aRgA
  .StartColumn = 2
  .EndColumn = 22
  .StartRow = 1
  .EndRow = 1298
  For j = 0 To 22
    .sheet = j
    rgs.addRangeAddress(aRgA, False)
  Next j
End With
rgs.clearContents(1023) REM To clear all content
End Sub

but got error “Call not allowed outside a procedure” https://i.imgur.com/BSQVqlO.png

You have 2 End Sub declarations.

...
End Sub
Call demo()
...
End Sub

hence everything after the first one is outside a procedure (and it makes absolutely no sense to use Call Sub and to repeat the code of that Sub. Either you use Call or integrate the code into a combined procedure - I prefer granularity of code and to implement what’s in my first comment)

There are texts about programming in LibreOffice Basic (and about using the API).
Recommendable: www.pitonyak.org/oo.php
We also have good reasons to still maintain schools instead of delegating their mission to forums and askbots.

Same Question as 10 Days ago