cancel
Showing results for 
Search instead for 
Did you mean: 

AutoOpen.xls and LibreOffice or OpenOffice

Former Member
0 Kudos

With the kind assistance of Christian Lohmaier and Eduardo Moreno on the Document Foundation's LibreOffice discussion mailing list, I have managed to modify AutoOpen.xls to work with both Excel and LibreOffice (and potentially OpenOffice, though I haven't tested it).

For my company, this means we can use the export-to-Excel functionality of SAP Business One without paying double for Excel by having to buy all new licenses in order to put it on our terminal server even though everyone already uses Excel on the desktop.

For anyone else who needs to support a free office suite: I'd love to attach the file as I have it, but I'm not sure copyright issues will allow that; instead, I'm going to show you how to modify the AutoOpen.xls file you already have.

1. Use Microsoft Excel to open AutoOpen.xls and then view the Visual Basic modules. (In my experience, you must use Excel for this, because LibreOffice will strip out the very macro you're working on when you save the document out as an .xls file!)

2. Find the subroutine named OpenExlFile(). In my file, it was located in Module 2.

3. Don't delete the body of that function, but wrap it with this code:

Attempt1:

    On Error GoTo Fail1

   

    ' Assume we're running Microsoft Excel

   

    !####### Here's where the existing function body goes ########

    Exit Sub

   

Fail1:

    Resume Attempt2

Attempt2:

    On Error GoTo Fail2

   

    ' Perhaps we're running LibreOffice or OpenOffice

   

    StarOpenTsvFile (excelPath)

Fail2:

    Exit Sub

4. Add this new subroutine in the same module:

Public Sub StarOpenTsvFile(tsvPath As String)

    Dim starDesktop As Object

    Dim url As String

    Dim doc As Object

    Dim parms(1) As New com.sun.star.beans.PropertyValue

    parms(0).Name = "FilterName"

    parms(0).Value = "Text - txt - csv (StarCalc)" ' Name is incorrect, but required

    parms(1).Name = "FilterOptions"

    parms(1).Value = "9,,65535,1" ' Tab seps, no string delim, UTF-16 charset, begin at line 1

    starDesktop = createUnoService("com.sun.star.frame.Desktop")

    url = ConvertToUrl(tsvPath)

    doc = starDesktop.loadComponentFromURL(url, "_blank", 0, parms)

End Sub

5. While I was in AutoOpen, I cleaned it up a little by deleting the empty code modules and spreadsheets. On the one spreadsheet left, I added a text box with a request that the user close the workbook immediately.

This battle was hard fought. I hope putting this information out there helps someone else

Accepted Solutions (0)

Answers (1)

Answers (1)

fbio_bilicki
Active Contributor
0 Kudos

Perfect, thank you,

worked perfectly in LibreOffice 4.3.3.2

http://www.libreoffice.org/

Rgs,

Fabio

SAP 8.82 PL14 / SAP 9.1 PL3