Ask Your Question
0

Detect if VBA is running under LibreOffice or Excel [closed]

asked 2013-04-25 23:13:48 +0200

Noxsc gravatar image

I have some Excel spreadsheets with VBA macros that almost run under both Excel and LibreOffice Calc. I can tweak the code to work with either. Is there an easy way for the macro to detect at runtime which software it is running on, so I can execute different code accordingly? I've been mandated to migrate our whole business to LO, and during the transition we need to be able to use certain files with both programs.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2015-10-30 20:47:40.014165

Comments

Thanks JohnSUN. That approach doesn't work, unfortunately. Excel reports a "compile error" on the line that starts with "if (Not GlobalScope..." Since it is a compilation error, the on error statement doesn't trap it. This may make what I am trying to do hopeless: In most cases, the code written for LO is going to prevent the whole macro from compiling.

Noxsc gravatar imageNoxsc ( 2013-04-29 15:51:50 +0200 )edit

Thanks JohnSUN. That approach doesn't work, unfortunately. Excel reports a "compile error" on the line that starts with "if (Not GlobalScope..." Since it is a compilation error, the on error statement doesn't trap it.

Noxsc gravatar imageNoxsc ( 2013-04-29 15:51:53 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2013-04-26 21:24:32 +0200

JohnSUN gravatar image

May be so?

Public isOpenOffice As Boolean

Private Sub Workbook_Open()
isOpenOffice = isLiO
If isOpenOffice Then
    MsgBox "Calc run.", vbOKOnly + vbInformation, "Info"
Else
    MsgBox "Excel run.", vbOKOnly + vbInformation, "Info"
End If
End Sub

Function isLiO() As Boolean
Dim oDoc
    isLiO = False
    On Error GoTo NotLiO
    If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then GlobalScope.BasicLibraries.LoadLibrary ("Tools")
    isLiO = True
NotLiO:

End Function
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-25 23:13:48 +0200

Seen: 1,771 times

Last updated: Apr 26 '13