Change text color of Calc form control with macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
skradus
Posts: 7
Joined: Mon Sep 27, 2010 8:52 pm

Change text color of Calc form control with macro

Post by skradus »

I'm trying to write a Basic macro that changes the text color of a form button in Calc (v. 3.2.0 for Ubuntu 10.04.1) when the user clicks on the button.

The Control Element Forms reference at http://wiki.services.openoffice.org/wik ... ment_Forms lists a TextColor (long) property, which it defines as "text color of control element." I'm guessing that this is what I am looking for. However, when I write:

Code: Select all

Sub ButtonClick(oEvent)
Button = oEvent.Source
Button.TextColor = RGB(255,255,255)
End Sub
assign ButtonClick to the button, and press the button, Calc returns the error: "BASIC runtime error. Property or method not found: TextColor." I have also tried CharColor, but that gives the same result.

Can anyone tell me what I am doing wrong?

Many thanks,
skradus
OpenOffice 3.2.0 on Ubuntu 10.04.1
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Change text color of Calc form control with macro

Post by B Marcelly »

Hi,
The Basic Guide wrote:The model object of a form button provides the following properties:
The Source property of an event provides the view of the control. You have to get the model from the view.

Code: Select all

Button = oEvent.Source
Button.Model.TextColor = RGB(255,255,255)
Yes, that is not obvious from the Basic Guide pages...
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
FJCC
Moderator
Posts: 9615
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Change text color of Calc form control with macro

Post by FJCC »

This is a an excellent example of why you should get an object inspection tool like xray.
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.
skradus
Posts: 7
Joined: Mon Sep 27, 2010 8:52 pm

Re: Change text color of Calc form control with macro

Post by skradus »

Brilliant. Thank you.
OpenOffice 3.2.0 on Ubuntu 10.04.1
Post Reply