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

如何将Excel VBAmacros移植到OpenOffice基本macros?

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

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 

我试着将这个macros转换成OpenOfficemacros(使用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中作为Object。

如何使它在OpenOfffice中工作?

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

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

  • 这太长了。 您需要按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。

有关许多优秀示例的OpenOfficemacros的介绍,请参见Andrew Pitonyak的macros文档 。

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

“我需要在OpenOffice Basic中select单元格A1,看着(在线源代码),我尝试了X,但它给出了关于行Z的Y错误信息。