OO 4.0.1 Macro Basic

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
DannyDontOO4
Posts: 2
Joined: Sun Nov 10, 2013 9:54 pm

OO 4.0.1 Macro Basic

Post by DannyDontOO4 »

I recently installed OO 4.0.1 and saw that the Marco Coding language has changed and is more like VBA. I have a rather complex Excel application that I have wanted to convert to OO but thought it impossible with the previous language used in OO Macros. Now it seems that most of the code converts very well. However, it appears that operations involving Files and other "system" accessing, still appears to be an issue. I am wondering if there is some resource that I might use to help understand what changes are necessary to make File Reading, Writing, Creating, Deleting, etc. I thank you in advance for any help you might provide.
Dan
Open Office 4.0.1 on Windows 7 - Service Pack 1
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: OO 4.0.1 Macro Basic

Post by rudolfo »

You might notice from my signature that OpenOffice can use several different programming languages for building macros. That's StarBasic, Python, Javascript, Java and C# to name the most prominent. The only language that looks a bit like VBA is StarBasic. And frankly I am not aware of any significant change since Sun OpenOffice Version 2.3.
Regarding Excel and Calc there is a nice cross reference guide available on the net, that will tell you what you have to change to make your original macro for Excel work with the UNO Object model of OpenOffice.

One major difference between Excel and Calc is that Calc/OpenOffice was designed to run on several different platforms (Unix, Mac, Windows,..) while Excel was always a MS Windows centric application. Take any of your complex macros and try to run it in MS Excel on a Macintosh computer ... and you will see what I mean: Excel on a Macintosh doesn't support the full feature set of Excel VBA on Windows.

OpenOffice decided to use a generic approach to handle file names. It makes use of the lingua franca for files and/or resources: URL notation. This means that you have a potential conflict in your macros: If you talk to the UNO objects of OpenOffice (paragraphs in Writer, spreadsheets, presentations,...) you have to use the URL style to describe files. But if you work with the File I/O functions of Basic (the often underestimated online help has a section about I/O functions in F1-Help --> Macros and Programming --> Command Reference --> Runtime Functions, Statements, Operators --> File I/O Functions) you need to use the notation of the OS you are working on. Actually the Online Help says: "If you want, you can enter a path in URL notation." So it seams that both approaches are supported. But this flexibility applies only to some functions like Dir or FileCopy, but not to Open.

OpenOffice Basic offers conversion functions ConvertFromUrl and ConvertToUrl to convert the OS filesystem name to an URL and vice versa.

And if you get stuck at a certain point just use this VBA function or statement and enter it in the search box of this forum. There are some chances that you find a solution for a similar problem.

If you get nowhere there is still another chance: OpenOffice has a COM Automation Interface. You can initiate the COM service of OpenOffice with a CreateObject call from within VBA or from VBS (Visual Basic Script) and automate OpenOffice with VBA or VBS. VBA is somehow a contradiction, because the most common VBA interpreters are MS Word and MS Excel. And if you need to have Excel installed to use the COM Automation Interface of OpenOffice, you can as well do everything in Excel. But VBS is available out of the box on any MS Windows system since Windows 2000, it is the Windows Scripting Host (WSH).
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
DannyDontOO4
Posts: 2
Joined: Sun Nov 10, 2013 9:54 pm

Re: OO 4.0.1 Macro Basic

Post by DannyDontOO4 »

It appears that my Quick Post may not have been sent??? In any case I thank you for the info. I have begun to look the the reference that you told me about. It seems to be a good one. Would you be willing to have me send a snippet of VBA code and have you show how it might be written in SBasic??? It might help me get started. Let me know and I will pick out something.
THANKS! in any case.
Open Office 4.0.1 on Windows 7 - Service Pack 1
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: OO 4.0.1 Macro Basic

Post by rudolfo »

I am not sure if I can do more with your VBA code then you can. The last time I worked with MS Word or MS Excel macros is 5 or 6 years ago. At that time I had the VBA online help of Office 2000 installed on my work computers, because I don't speak VBA fluently. So I had to look up every other line in the online help to understand what it does. This hasn't improved since then. It rather got worse. And at the moment I haven't installed MS Office.

So if you don't comment your VBA code to explain what it does or what it is supposed to do, there is nearly no chance that I can find the appropriate counterpart in StarBasic.

But I can give it a try. And at least I will be able to look at the code and figure out what kind of additional COM objects it uses. Because COM is so tightly integrated into VBA very often VB(A) coders are not aware that they are not only using MS-Office, but also other utilities. Sometimes it is possible to use this other COM utilities also from within StarBasic and OpenOffice, but that's not guaranteed.

You always have the choice to post 15 and 20 lines of code directly here in the forum. Just don't forget to surround this code snippet with [ code ] and [ /code ] bb-code tags (without the space after the opening bracket and before the closing bracket) for the sake of readability.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Post Reply