如何将用户选择范围的范围地址存储在变量中

问题描述 投票:0回答:1

我想要一个变量来存储用户选择的范围的“范围地址”(例如“B2:E4”)。

我正在尝试以下方法:

Sub print_selected_range

Dim oSheet as Object
Dim MyChoice as Object

oSheet = ThisComponent.CurrentController.getActiveSheet()
MyChoice = oSheet.getRangeAddress()
    
Print MyChoice
    
End Sub

这会导致错误:

什么方法会产生这个范围?我在其他地方找到的下面的代码有点接近我想要的:

Sub get_range_address

    oActiveCell = ThisComponent.getCurrentSelection()
       
    oConv = ThisComponent.createInstance("com.sun.star.table.CellRangeAddressConversion")
    oConv.Address = oActiveCell.getRangeAddress
    
    msgbox  oConv.UserInterfaceRepresentation & _
      "  " & oConv.PersistentRepresentation

End Sub

但是,我不知道如何提取范围地址并转储 它变成一个变量,而且它很复杂,我真的想要 简单的代码(如上面的第一个代码块),以便稍后我快速记住/理解发生了什么并快速将其应用到其他地方。

range libreoffice-calc libreoffice-basic
1个回答
0
投票

我希望这段代码足够短且易于理解,无需进一步解释:

Sub print_selected_range
Dim sAddressOffSelection As String 
    sAddressOffSelection =  ThisComponent.getCurrentSelection().AbsoluteName
    MsgBox "Current selection is " & sAddressOffSelection
End Sub 
© www.soinside.com 2019 - 2024. All rights reserved.