Difference between revisions of "Documentation/OOoAuthors User Manual/Getting Started/Writing macros without the recorder"
From Apache OpenOffice Wiki
(Clean up TOC and category references) |
(Added color coding to the wiki) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{DISPLAYTITLE:Writing macros without the recorder}} | ||
{{Documentation/GSMacroTOC | {{Documentation/GSMacroTOC | ||
|ShowPrevNext=block | |ShowPrevNext=block | ||
Line 4: | Line 5: | ||
|NextPage=Documentation/OOoAuthors User Manual/Getting Started/Finding more information | |NextPage=Documentation/OOoAuthors User Manual/Getting Started/Finding more information | ||
}} | }} | ||
− | |||
− | |||
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 OpenOffice.org. In other words, you can directly manipulate a document. | 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 OpenOffice.org. In other words, you can directly manipulate a document. | ||
Line 12: | Line 11: | ||
''Listing 4: Append the text “Hello" to the current document.'' | ''Listing 4: Append the text “Hello" to the current document.'' | ||
− | < | + | <source lang="oobas"> |
Sub AppendHello | Sub AppendHello | ||
Dim oDoc | Dim oDoc | ||
Line 37: | Line 36: | ||
oCurs.Text.insertString(oCurs, "Hello", False) | oCurs.Text.insertString(oCurs, "Hello", False) | ||
End Sub | End Sub | ||
− | </ | + | </source> |
{{Manual}} | {{Manual}} | ||
[[Category:Getting Started (Documentation)]] | [[Category:Getting Started (Documentation)]] |
Latest revision as of 22:19, 5 January 2013
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 OpenOffice.org. 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 = "com.sun.star.text.TextDocument" 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 oCurs.gotoEnd(False) REM Insert text "Hello" at the end of the document oCurs.Text.insertString(oCurs, "Hello", False) End Sub
Content on this page is licensed under the Creative Common Attribution 3.0 license (CC-BY). |