Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I think that you meant something like the following code

Sub cyclBySelectedSheets
Dim oCurrentSelection As Variant
Dim fullRangeAddress As String
Dim tmpArray As Variant
Dim oSheets As Variant
Dim oSheet As Variant
Dim i&
    oCurrentSelection = ThisComponent.getCurrentSelection()
    fullRangeAddress = oCurrentSelection.AbsoluteName
    fullRangeAddress = Join(Split(fullRangeAddress,"$"),"")
    oElementNames = Split(fullRangeAddress,";")
    oSheets = ThisComponent.getSheets()
    For i = LBound(oElementNames) To UBound(oElementNames)
        tmpArray = Split(oElementNames(i),".")
        oSheet =  oSheets.getByName(tmpArray(0))
REM Do something with this sheet... For example:
        Print "Processing " + oSheet.getName()
    Next i  
End Sub

I think that you meant something like the following code

Sub cyclBySelectedSheets
cycleBySelectedSheets
Dim oCurrentSelection As Variant
Dim fullRangeAddress As String
Dim tmpArray As Variant
Dim oSheets As Variant
Dim oSheet As Variant
Dim i&
    oCurrentSelection = ThisComponent.getCurrentSelection()
    fullRangeAddress = oCurrentSelection.AbsoluteName
    fullRangeAddress = Join(Split(fullRangeAddress,"$"),"")
    oElementNames = Split(fullRangeAddress,";")
    oSheets = ThisComponent.getSheets()
    For i = LBound(oElementNames) To UBound(oElementNames)
        tmpArray = Split(oElementNames(i),".")
        oSheet =  oSheets.getByName(tmpArray(0))
REM Do something with this sheet... For example:
        Print "Processing " + oSheet.getName()
    Next i  
End Sub

But if you mean "select some sheets, with Ctrl key select some ranges on them and then work with each of this selections" so

Sub cycleBySelectedRanges
Dim oCurrentSelection As Variant
Dim oSheets As Variant
Dim oRanges As Variant
Dim oRange As Variant
Dim i&
    oCurrentSelection = ThisComponent.getCurrentSelection()
    oSheets = ThisComponent.getSheets()
    oRanges = oSheets.getCellRangesByName(oCurrentSelection.AbsoluteName)
    For i = LBound(oRanges) To UBound(oRanges)
        oRange = oRanges(i)
REM Do something with this range...
        Print "Processing " + oRange.AbsoluteName
    Next i  
End Sub