Administration Manual

Table Of Contents
Distributing OpenOffice.org Basic Libraries
To Install a Custom OpenOffice.org Basic Library With a
Macro
You can create a macros that installs a OpenOffice.org Basic library from an OpenOffice.org document.
1 In Writer, create a custom OpenOffice.org Basic library in a new document.
2 Save the document.
3 Create an installation macro.
a. Choose Tools โ†’ Macros โ†’ Organize Macros โ†’ OpenOffice.org Basic. The OpenOffice.org
Basic Macros dialog box appears.
b. In the Macro from list, select your Writer document.
c. In the Macro name box, type a name from the installation macro.
d. Click the New button. The BASIC IDE window appears.
e. Type the following code:
Sub AddBasicLibrary
Dim SourceLibraryName As String, DestLibraryName As String
Dim oSrcLib As Object, oDestLib As Object, iCounter As Integer
Dim oLib As Object, oGlobalLib As Object
' set these 2 variables to your lib name
SrcLibraryName = "TextLib"
' The name of the library that contains the modules
DestLibraryName = "NewLib"
' This library will be created and is the
' destination for the modules from the source document.
oLib = BasicLibraries ' For Basic libaries
oGlobalLib = GlobalScope.BasicLibraries
For iLib = 1 To 2
If oGlobalLib.hasByName( DestLibraryName ) = False Then
oGlobalLib.createLibrary( DestLibraryName )
End If
If oLib.hasByName( SrcLibraryName ) Then
oLib.loadLibrary( SrcLibraryName )
oSrcLib = oLib.getByName( SrcLibraryName )
sSrcModules = oSrcLib.getElementNames()
iCounter = lBound( sSrcModules() )
while( iCounter <= uBound( sSrcModules() ) )
oDestLib = oGlobalLib.getByName(DestLibraryName)
If oDestLib.hasByName( sSrcModules(iCounter) ) = False Then
oDestLib.insertByName( sSrcModules(iCounter),_
oSrcLib.getByName( sSrcModules(iCounter) ) )
End If
iCounter = iCounter + 1
wend
End If
oLib = DialogLibraries ' The same for the Dialog libraries
oGlobalLib = GlobalScope.DialogLibraries
Next iLib
End Sub
f. Replace the SrcLibraryName and DestLibraryName variables with the name of
your library.
g. Close the BASIC IDE window.
4 Add a push button to the document.
a. On the Form Controls toolbar, click the Push Button icon.
b. In your document, drag to draw the button.
5 Assign the installation macro to a button event.
16 OpenOffice.org 3.2 Administration Guide ยท March 2010