Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




OpenOffice 3.x Getting Started Guide
Previous Page Home Next Page

The examples covered in this chapter are created using the macro recorder and the dispatcher. You can also write macros that directly access the objects that comprise In other words, you can directly manipulate a document.

Directly manipulating OOo's internal objects is an advanced topic that is beyond the scope of this chapter. A simple example, however, demonstrates how this works.

Listing 4: Append the text “Hello" to the current document.

 Sub AppendHello
   Dim oDoc
   Dim sTextService$
   Dim oCurs
   REM ThisComponent refers to the currently active document.
   oDoc = ThisComponent
   REM Verify that this is a text document  
   sTextService = ""
   If NOT oDoc.supportsService(sTextService) Then
     MsgBox "This macro only works with a text document"
     Exit Sub
   End If
   REM Get the view cursor from the current controller.
   oCurs = oDoc.currentController.getViewCursor()
   REM Move the cursor to the end of the document
   REM Insert text "Hello" at the end of the document
   oCurs.Text.insertString(oCurs, "Hello", False)  
 End Sub

OpenOffice 3.x Getting Started Guide
Previous Page Home Next Page

  Published under the terms of the Creative Commons License Design by Interspire