Regard what @Zizi64 wrote.
However, the subject may attract visitors actually looking for multipüle-sheet-selection by macros independent of printing.
I don’t know how to simulate the “Ctrl+Click” on a sheet’s tab directly, but we can take SheetCellRange
addresses from a first sheet, change them to a different sheet, add them to the SheetCellRanges
, and finally select what we got.
When I tried this I even was slightly surprised that it worked, and the multi-sheet selection also visualized the result correctly.
A .uno:
fopr the purpose (not yet exiosting) would probably need to do it the same way.
See demo code below.
Function expandSheetCellRangesIncludingAdditionalSheet(_
Optional pRanges As Object, _
Optional pAdditionalSheetIndex1based As Long) As Object
REM Very raw!! No error catching.
If IsMissing(pAdditionalSheetIndex1based) Then pAdditionalSheetIndex1based = 3 REM Demo!!
index0based = pAdditionalSheetIndex1based - 1
doc = ThisComponent
cCtrl = doc.CurrentController
If IsMissing(pRanges) Then pRanges = cCtrl.Selection
If pRanges.supportsService("com.sun.star.sheet.SheetCellRanges") Then
myRgs = pRanges
Else
myRgs = doc.createInstance("com.sun.star.sheet.SheetCellRanges")
myRgs.addRangeAddress(pRanges.RangeAddress, False)
EndIf
u0 = myRgs.Count - 1
For r = 0 To u0
r_rg = myRgs(r)
r_ra = r_rg.RangeAddress
r_ra.Sheet = index0based
myRgs.addRangeAddress(r_ra, False)
Next r
expandSheetCellRangesIncludingAdditionalSheet = myRgs
REM For demo only
cCtrl.select(myRgs)
newSel = cCtrl.Selection
End Function