Language Selection

English French German Italian Portuguese Spanish

OOoBasic crash course: Working with files

Filed under
HowTos

OpenOffice.org's OOoBasic gives users tools to programmatically access and manipulate files. To see how that works, we'll create a simple macro that allows you to save text snippets from the current document in a plain text file. This macro can be used to store text fragments from multiple documents in one text file, or to save deleted passages in an external file in case you need them later.

To build this macro, you can reuse the component that grabs the selected text fragment in the current document. If you've followed the previous installments of the OOoBasic crash course series on creating a lookup macro and working with words, the following code will look familiar:

Sub WriteFile()
Dim oDoc As Object, oText As Object
Dim oCursor As Object
Dim sFileName As String
oDoc=ThisComponent
oText=oDoc.Text
oCursor=oDoc.CurrentController.getViewCursor
If oCursor.String ="" then MsgBox "Please select a word to look up" : End

Notice the sFileName variable, defined as string. This variable points to the file for use in the macro. To specify the file you want, use the following code:

Full Story.

More in Tux Machines

Android Leftovers

Tizen Samsung Z1, made in India and soon to be available in Bangladesh

As we have reported Samsung has been sending the parts for its Samsung Z1 SM-Z130H/DS to be assembled at its Noida plant in India, which has the capacity to produce over 4 million handsets per month. The Samsung Z1 was launched in India as the first Tizen based commercial handset at a competitive price of 5,700 INR. Read more

Ubuntu 15.04 to Integrate Linux Kernel 3.19 Branch Soon

The Linux kernel is one of the most important components in a distribution and Ubuntu users are interested to know what will be used in the stable edition for the 15.04 branch, which is scheduled to arrive in a couple of months. Read more

Locally Integrated Menus Can Be Set to Always Show in Ubuntu 15.04

The development cycle for Ubuntu 15.04 still have a couple of months left and the guys and gals from Canonical are making good progress. An important improvement regarding the use of menus in the title bar has been implemented and it will be part of the stable edition that will launch in April. Read more