【问题标题】:How to port Excel VBA to OpenOffice basic?如何将 Excel VBA 移植到 OpenOffice 基础版?
【发布时间】:2016-02-24 04:42:17
【问题描述】:

如何将 Excel VBA 宏移植到 OpenOffice 基本宏?

这里是每 5 秒刷新一次的宏。

Private Sub Workbook_Open()
' Written in ThisWorkbook
Call RefreshTime
End Sub

Sub RefreshTime()
' Written in a module
Application.ScreenUpdating = False
ActiveWorkbook.RefreshAll
Application.OnTime Now + TimeValue("00:00:05"), "RefreshTime"
Range("B10").Value = "My Current Time of the System:"
Range("C10").Value = Format(Now, "hh:mm:ss AM/PM")
Beep
Application.ScreenUpdating = True

End Sub

我尝试将此宏转换为 OpenOffice 宏(使用 http://www.business-spreadsheets.com/vba2oo.asp

Private Sub Workbook_Open()
' Written in ThisWorkbook
Call RefreshTime
End Sub
Sub RefreshTime()
' Written in a module
ThisComponent.LockControllers
ThisComponent.RefreshAll
Application.OnTime Now + TimeValue("00:00:05"), "RefreshTime"
ThisComponent.CurrentController.ThisComponent.CurrentController.ActiveSheet.getCellDim oSheet as Object[n]oSheet = ThisComponent.CurrentController.ActiveSheet[n]oSheet.getCellRangeByName($1)ByName(("B10")).Value = "My Current Time of the System:"
ThisComponent.CurrentController.ThisComponent.CurrentController.ActiveSheet.getCellDim oSheet as Object[n]oSheet = ThisComponent.CurrentController.ActiveSheet[n]oSheet.getCellRangeByName($1)ByName(("C10")).Value = Format(Now, "hh:mm:ss AM/PM")
Beep
ThisComponent.UnlockControllers
End Sub

这行代码导致语法错误的是:

ThisComponent.CurrentController.ThisComponent.CurrentController.ActiveSheet.getCellDim oSheet as Object[n]oSheet =  ThisComponent.CurrentController.ActiveSheet[n]oSheet.getCellRangeByName($1)ByName(("B10")).Value = "My Current Time of the System:"

但有错误

基本语法错误。预期:,。

在 oSheet 中作为对象。

如何让它在 OpenOffice 中运行?

【问题讨论】:

  • 又是哪一行代码导致语法错误?
  • 这行代码导致语法错误:oSheet in ThisComponent.CurrentController.ActiveSheet.getCellDim oSheet as Object
  • 谢谢,这将对了解 OO Basic 的人有所帮助。由于您是新手,您可能不知道可以单击问题下方的“编辑”按钮来添加其他信息。在这种情况下,我已经为您完成了 :-) 祝您迁移顺利!

标签: vba excel openoffice-basic


【解决方案1】:

此代码似乎存在许多问题。我们来看看这一行:

ThisComponent.CurrentController.ThisComponent.CurrentController.ActiveSheet.getcellDim oSheet as Object[n]oSheet = ThisComponent.CurrentController.ActiveSheet[n]oSheet.getCellRangeByName($1)ByName(("B10")).Value = "My Current系统时间:"

  • 太长了。您需要按 Enter 来添加多个换行符。
  • 它说“ThisComponent.CurrentController”两次。
  • Dim oSheet as Object[n] -- 但 n 从未被声明或定义。
  • ActiveSheet.getcell -- 我不知道有任何这样的方法。见https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Cells_and_Ranges
  • ByName(("B10")) -- 括号太多,同样没有“ByName”这样的方法。
  • 什么是$1?也许您的意思是像"$A1:$A5" 这样的范围。

还有:

  • Private Sub Workbook_Open -- 看起来像 VBA,而不是 OpenOffice Basic。

有关 OpenOffice 宏的介绍以及许多出色的示例,请参阅 Andrew Pitonyak's Macro Document

不要说:“这是 Excel VBA 中的代码;OpenOffice Basic 中的代码是什么?”,而是在 stackoverflow 上提出如下问题:

“我需要在 OpenOffice Basic 中选择单元格 A1。查看(在线资源),我尝试了 X,但它给出了关于 Z 行的 Y 错误消息。”

【讨论】:

  • 很好的答案,虽然我不同意你的评论“这是 Excel VBA 中的代码;OpenOffice Basic 中的代码是什么?”它们是不同的平台和语言,但它们都是电子表格,而且 OpenOffice 在设计上甚至有点类似于 Microsoft Office。它们在许多方面完全不同的事实只是意味着所需的移植不是纯粹机械的。
  • @JohnColeman:好的,我稍微缓和了我的发言。真的,我对 VBA 不是很熟悉。当我“移植”宏时,我通常会查看 GUI 前端并阅读 Excel 宏的帮助,然后用一种支持 OpenOffice UNO 的语言重写该功能。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-10
  • 2021-11-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多