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

The Linux Foundation Now Offers Courses in Spanish and Portuguese

The Linux Foundation has announced that Certified System Administrator (LFCS) exams have been made available in the Spanish and Portuguese languages. Also, the Essentials of Linux System Administration course (LFS201) can now be taken in Portuguese as well. Read more

Reasons Why Users Don't Like Ubuntu Software Center

The majority opinion in the Ubuntu community seems to be that the Ubuntu Software Center is a terrible piece of software and that it needs to be replaced or fixed urgently. We compiled a list of reasons why users don't like the application and why they think Canonical should really consider a change. Read more

15 Android Apps to Remote Control Your Linux PC

There’s no reason why Linux and Android shouldn’t get along well—after all, they’re pretty much cousins. You’ve probably heard of apps that let you remotely control an Android device from the desktop. There are also apps that do the vice versa and make it possible to control a Windows computer from an Android device. Linux users need not feel left out. We’ve discovered more than enough apps that can turn your Androids into powerful Linux remote controllers, and today we’ll present some of our best findings. Read more

Linux Foundation's CII Donates $50k+ To OpenBSD

The Linux Foundation's Core Infrastructure Initiative (CII) has made a donation in the range of $50~100k USD to the OpenBSD project. Read more Also: Lumina Desktop 0.8.6 Released for PC-BSD 10.2 and FreeBSD 10.2, Here's What's New