Referencing Dialog Controls With Macros in Writer

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
coonyp
Posts: 4
Joined: Wed Jul 22, 2009 7:59 pm

Referencing Dialog Controls With Macros in Writer

Post by coonyp »

I have a relatively simple question that I can't find clearly answered in the Macro manual. I have developed a Dialog with a text box and have assigned the text box to a macro with a mouse event. The question is how do I reference the text in the text box and assign it to a global variable that I will use in the macro? Alternatively, is there a more efficient method for referencing the text box text, i.e. using it as a field for mail merge purposes? Since this is a rather fundamental use of Dialogs, shouldn't some code examples appear in the manual section pertaining to dialogs? I found the whole section very helpful except for this missing piece.
OOo 2.3.X on Ms Windows XP + Ms Windows Vista
FJCC
Moderator
Posts: 9650
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Referencing Dialog Controls With Macros in Writer

Post by FJCC »

Here is some code that runs a dialog with a text box and then gets the text from the box and prints it. If I understand what you are trying to do, there is no need to assign a macro to the text box itself. You have to modify the code to whatever name your text box has. You can find that by right clicking on the box when in design mode, selecting Properties and looking on the General tab.

Code: Select all

DialogLibraries.LoadLibrary( "Standard" )  'Load the standard Library
oDialog1 = CreateUnoDialog( DialogLibraries.Standard.Dialog1 )  'Load the existing Dialog called Dialog1
TextBox = oDialog1.getControl("TextField1")
oDialog1.execute()
Item = TextBox.Text
Print Item
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Post Reply