Click here to Skip to main content
15,886,857 members

Problem with VBA compatibility in libre office calc

Patrice T asked:

Open original thread
Hi all,
I have an Excel WorkBook with VBA macros, There is no problem with it on Excel.
As I try to open it on LO Calc, I got a lot of compatibility problems, I fixed them all but 1.
I fixed problems like conditional compilation (#If ... #End If) incompatibility.
I use Libre Office 6.1 Calc.
I use Libre Office 6.3 Calc.

I got 1 remaining error on this code:
VB
Function Extract(Chaine, Optional Pos = 1, Optional Balise)
    If IsNumeric(Chaine) Then
        ' c'est numerique, on retourne la valeur
        Extract = Chaine
        Exit Function
    End If
    Set re = CreateObject("VBScript.RegExp")
    re.Global = True
    If IsMissing(Balise) Then
        '   pas de balise, on cherche les valeurs numeriques
        re.pattern = "[0-9,.]+"

        Set A = re.Execute(Chaine)  ' Error here
        If A.Count >= Pos Then Extract = val(Replace(A(Pos - 1), ",", "."))
    Else
        '   la balise sert de séparateur
        re.pattern = Balise
        B = Strings.Split(re.Replace(Chaine, vbNullChar), vbNullChar)
        If B.Count >= Pos Then Extract = val(Replace(B(Pos - 1), ",", "."))
    End If
End Function

Error Message:
Erreur d'exécution BASIC.
'1'

Type: com.sun.star.script.CannotConvertException
Message: [automation bridge]UnoConversionUtilities<T>::anyToVariant 
Cannot convert the value of type :"com.sun.star.uno.XInterface"  to the expected Automation type of VARTYPE: 8

The execute is supposed to return collection of object.
Usage:
A1= "100x10x150"
A2= Extract(A1) => 100
A3= Extract(A1,2) => 10
A4= Extract(A1,3) => 150

What I have tried:

This code works perfectly in Excel, but fail to compil in Calc.
What did I missed?
Tags: VBA, LibreOffice

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900