如何将Excel VBA移植到OpenOffice基础?

时间:2016-02-24 04:42:17

标签: excel vba excel-vba openoffice-basic

如何将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:"

但有错误

  

BASIC语法错误。预期:

在oSheet中作为对象。

如何在OpenOfffice中使用它?

1 个答案:

答案 0 :(得分:1)

此代码看起来有很多问题。我们来看看这一行:

  

ThisComponent.CurrentController.ThisComponent.CurrentController.ActiveSheet.getcellDim oSheet as Object [n] oSheet = ThisComponent.CurrentController.ActiveSheet [n] oSheet.getCellRangeByName($ 1)ByName((" B10"))。值="我当前的系统时间:"

  • 太长了。您需要按 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错误消息。"