Programming OpenOffice: Using Dialogs in Macros

How to Use a Dialog to Obtain Data for an OpenOffice.org Macro

© Mark Alexander Bain

OpenOffice is a powerful suite of tools, and creating Basic Macros makes it even more versatile. Adding dialogs just gives it that human touch.

OpenOffice.org is a invaluable tool to everyone in today's office environment, consisting of:

All of this means that it is very easy for anyone to build a complex application, carrying out all of the business operations required in day to day life. Unfortunately, these applications soon become very complicated and difficult for a new user to understand. Fortunately, it is also very easy to make life much simpler by:

OpenOffice's Built-in Dialogs

OpenOffice's built-in Dialogs are very simple, and are designed to enable the application to supply information to the user, or to obtain limited information from them. The two types are:

OpenOffice's Message Box

The message box is a simple way of outputting information to a user, and allowing them some simple responses; for example this macro has a little conversation with the user:

Sub Main

Dim ip as Integer

mf = msgbox ( "Are you male?", 4, "Application Question")

select case mf

case 6

msgbox "You've said that you're male", 0, "Application Confirmation"

case 7

msgbox "You've said that you're female", 0, "Application Confirmation"

end select

End Sub

This macro uses the message box in two ways:

In each case the variables required by the message box are the same:

OpenOffice's Input Box

The input box is as easy to use as the message box - however, this time the user response is always saved into a variable, for example:

username = InputBox ("Please enter your name","Application Information")

The input box just needs two inputs:

Using Message Boxes and Input Boxes with OpenOffice Calc

With just these two OpenOffice Basic methods it is possible to greatly simplify the process of entering data into an OpenOffice document:

Sub Main

Dim ip as Integer

Dim oCell

'Get user name

oCell = thisComponent.Sheets(0).getCellRangeByName("B1")

oCell.String = "Name:"

oCell = thisComponent.Sheets(0).getCellRangeByName("B1")

oCell.String = InputBox ("Please enter your name","Application Information")

'Is user male or female?

oCell = thisComponent.Sheets(0).getCellRangeByName("A7")

oCell.String = "M/F"

oCell = thisComponent.Sheets(0).getCellRangeByName("B7")

mf = msgbox ( "Are you male?", 4, "Application Question")

select case mf

case 6

oCell.String = "Male"

case 7

oCell.String = "Female"

end select

'Get user age

oCell = thisComponent.Sheets(0).getCellRangeByName("C7")

oCell.String = "Age:"

oCell = thisComponent.Sheets(0).getCellRangeByName("D7")

oCell.Value = InputBox ("Please enter your age","Application Information")

End Sub

By introducing the message boxes and input boxes a user does not need to know anything about the structure of the document, or what information is needed - all they have to do is to answer the questions posed to them by the macro.


The copyright of the article Programming OpenOffice: Using Dialogs in Macros in Office/Business Software is owned by Mark Alexander Bain. Permission to republish Programming OpenOffice: Using Dialogs in Macros in print or online must be granted by the author in writing.





Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo