【问题标题】:Jump to Cell Based on Value in Another Cell (Macro LibreOffice VBA)根据另一个单元格中的值跳转到单元格(宏 LibreOffice VBA)
【发布时间】:2015-11-25 08:02:49
【问题描述】:

我希望能够根据用户输入的日期(在 B14 中)跳转到一个单元格。 在 F 列中,我有一个日期列表(从第 8 行开始)。 到目前为止,我有=MATCH(B14,F8:F373)+7(在 B15 中)计算正确日期在哪一行,并返回一个数字。

我需要在 LibreOffice VBA 中编写一个宏,该宏将在 G 列中选择该行中的单元格。到目前为止,我有:

sub jump

dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

Doc = ThisComponent
Sheets=Doc.Sheets
sheet=Sheets.getByName("ThisYear")

dim args1(0) as new com.sun.star.beans.PropertyValue

thisrow =sheet.getCellByPosition(15,2).getValue()

args1(0).Name = "ToPoint"
args1(0).Value = (G,thisrow)

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

end sub

但它不接受形式(列、行)中的值。我以前见过我需要像args1(0).Value = "G15" 这样的东西,但我怎样才能包含变量? (我试过用 7 代替 G 但这没有帮助。)

我已经提到了工作表名称sheet=Sheets.getByName("ThisYear"),但它都在一张工作表中,所以理想情况下我不想指定这个,所以我可以在不同的工作表中使用宏。

我是 VBA 新手,所以请用整个子回复。

谢谢!

【问题讨论】:

    标签: libreoffice-basic


    【解决方案1】:

    我了解到您在弄清楚如何更改 LibreOffice Calc 中的单元格选择时遇到了问题。这是一个代码 sn-p 向您展示如何。简而言之,您确定一个目标范围 (oRange)(下面是位于位置 3,3 的单个单元格),然后将该对象传递给 .select() 方法。

    Sub ChangeSelection
      oSheets = ThisComponent.Sheets
      oSheet = oSheets.getByIndex(0)
      oRange = oSheet.getCellByPosition(3,3)
      ThisComponent.CurrentController.select(oRange)
    
    End Sub
    

    LibreOffice 使用记录在 here 的 UNO API。如果您想浏览对象的属性和方法,请使用MsgBox oObject.DBG_properties.DBG_methods,通常您最终将能够找到正确的东西。您问题中的代码 sn-p 返回一个我无法立即弄清楚的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多