如何使vba代码与libre office兼容

我最近从Windows迁移到pclinuxos似乎喜欢它。 我面临的唯一问题是,libreoffice,默认的电子表格包不兼容的Excelmacros。 下面是我有的vba代码:

Option VBASupport Sub DeleteToLeft() Selection.SpecialCells(xlBlanks).Delete shift:=xlToLeft End Sub Function SinceLastWash() Application.Volatile WashCount = 0 WearCount = 0 CurrentRow = Application.ThisCell.Row For i = 3 To 35 If Range(Cells(CurrentRow, i), Cells(CurrentRow, i)).Value = "a" Then WearCount = WearCount + 1 End If If Range(Cells(CurrentRow, i), Cells(CurrentRow, i)).Value = "q" Then WashCount = WashCount + 1 WearCount = 0 End If Next i SinceLastWash = WearCount End Function Function testhis() testhis = Application.ThisCell.Row End Function 

有没有办法转换这个代码,使其与libreoffice兼容,还是我必须学习像Python一样的全新语言? 学习Python不会是一个问题,但不是一个解决我的问题,因为我有很多工作相关的文件在Excel中有很多的VBA代码,这是不可能的,我在工作中使用的开放式办公室/ libreoffice …

我只是想补充说,函数SinceLastWash在我使用它的一些单元格中给出了正确的值,而在其他单元格中给出了一个错误,#NAME?

谢谢

从LibreOffice的在线帮助文​​件:

除less数例外,Microsoft Office和LibreOffice不能运行相同的macros代码。 Microsoft Office使用VBA(Visual Basic for Applications)代码,而LibreOffice使用基于LibreOffice API(应用程序接口)环境的基本代码。 虽然编程语言是一样的,但是对象和方法是不同的。

如果您在LibreOffice – PreferencesTools – 选项 – 加载/保存 – VBA属性中启用此function,LibreOffice的最新版本可以运行一些Excel Visual Basic脚本。

实际上,您很可能需要坐下来使用LibreOffice API并重写function。

我知道唯一的自动工具是商业电子表格 (请注意,我没有个人或专业经验,也没有任何与本网站的关系)。

这似乎是特定于OpenOffice,但我认为它也适用于LibreOffice。

一般来说,你最好自己做,因为这个工具远非完美…

在LibreOffice 4.4中,第一个子程序根本无法工作(我怀疑是因为所有以'xl'开头的variables,如果将ThisCell更改为ActiveCell,另外两个子程序完美工作。

而不是

 Option VBASupport 

我在用

 Option VBASupport 1 Option Compatible 

您必须翻译处理文档的部分才能使用UNO API。 不幸的是,这可能是棘手的,取决于你的macros是什么。 基本声明直接工作。 修改文档通常不会。

 Range(Cells(CurrentRow, i), Cells(CurrentRow, i)).Value = "a" 

单元格命令基于行和列返回特定的单元格。 所以,你需要当前行。 这里有一些疯狂的活动单元格:

 Sub RetrieveTheActiveCell() Dim oOldSelection 'The original selection of cell ranges Dim oRanges 'A blank range created by the document Dim oActiveCell 'The current active cell Dim oConv 'The cell address conversion service Dim oDoc oDoc = ThisComponent REM store the current selection oOldSelection = oDoc.CurrentSelection REM Create an empty SheetCellRanges service and then select it. REM This leaves ONLY the active cell selected. oRanges = oDoc.createInstance("com.sun.star.sheet.SheetCellRanges") oDoc.CurrentController.Select(oRanges) REM Get the active cell! oActiveCell = oDoc.CurrentSelection oConv = oDoc.createInstance("com.sun.star.table.CellAddressConversion") oConv.Address = oActiveCell.getCellAddress Print oConv.UserInterfaceRepresentation print oConv.PersistentRepresentation REM Restore the old selection, but lose the previously active cell oDoc.CurrentController.Select(oOldSelection) End Sub 

当你有活动单元格,你得到的单元格地址,并从那里,你有行。 你根本不需要使用范围,因为你只关心一个单元格,所以,你得到活动表单,然后从表单中获取一个特定的单元格。

像这样:ThisComponent.getCurrentController()。getActiveSheet()。getCellByPosition(nCol,nRow).getString()=“a”

我不想搞清楚这是干什么的

 Selection.SpecialCells(xlBlanks).Delete shift:=xlToLeft 

Selection.SpecialCells(xlBlanks).Delete shift:=xlToLeft删除空白单元格,如果我没有弄错