I noticed LibreOffice Basic evaluates the with expression every time the object is used within the block. This prevents optimizing some code where the object can be evaluated outside of a for/to loop, and then re-used for each iteration. Workaround is to evaluate the expression to an object and then use that object in the with expression. For example instead of: With getsheet Use: oSheet = getsheet With oSheet This is different behavior compared to Excel VBA, where the object expression is only evaluated at the start of the block. Verified in Excel 2010, almost certain 2007 was the same, but not sure about earlier versions. Example in LibreOffice Basic:- Sub Main Dim i As Integer With getsheet For i = 0 To 9 msgbox (.getCellByPosition(0, i).Value) Next i End With End Sub Function getsheet As Object msgbox "getsheet was called" getsheet = thisComponent.Sheets(0) End Function Similar example in Excel VBA:- Sub Main() Dim i As Integer With getsheet For i = 1 To 10 MsgBox (.Cells(i, 1).Value) Next i End With End Sub Function getsheet() As Worksheet MsgBox "getsheet was called" Set getsheet = ThisWorkbook.Sheets(1) End Function
Confirmed. Arch Linux 64-bit, KDE Plasma 5 Version: 5.2.0.0.alpha1+ Build ID: 540fee2dc7553152914f7f1d8a41921e765087ef CPU Threads: 8; OS Version: Linux 4.5; UI Render: default; Locale: fi-FI (fi_FI.UTF-8) Built on April 30th 2016
Let me mark it as a dupe of another one, which, even though filed later, describes the problems with this bug. *** This bug has been marked as a duplicate of bug 132064 ***