Macro copying a textbox

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
magalhaes88
Posts: 4
Joined: Thu Jul 14, 2016 2:13 am

Macro copying a textbox

Post by magalhaes88 »

Hello,

I'm having a hard time with a very simple macro I'm trying to write.
If any of you macroexpert could help me, I'd be very thankful.
Here's the deal:

I have created a form, where I'll put, inside a textbox, some data.
This data would be the name of a customer, and I need to re-write this name several times along the document.

So, I planned this macro:

Code: Select all

 Sub Macro1()
dim x as string
x= Textbox1.text
msgbox x
End Sub
The msgbox is only a test, used to check if the data inserted into the textbox1 was linked to the variable x.

Well, although simple, this macro simply doesn't work.
I just can't find how to copy the content of the textbox1 (that would be the name of the customer) and link it to the variable X.
I get an error of synthax message,

Can any of you gurus spot my noob mistake?

Thank you
OpenOffice 3.1 on Windows 7
UnklDonald418
Volunteer
Posts: 1573
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Macro copying a textbox

Post by UnklDonald418 »

Welcome to the Forum magalhaes88
You didn't provide a use profile so I am assuming you are using a recent version of Apache Open Office with an Embedded Database.
If there is a way to avoid using a Macro and there often is, then that is the way to go because writing Macros has a steep learning curve. Your code comes nowhere near accomplishing what you seek.
Andrew Pitonyak's book OpenOffice.org Macros Explained is available for free download from http://www.pitonyak.org/oo.php
If you are serious about writing Base Macros then the book by Roberto Benitez OpenOffice.org Base & Basic is very good, but it isn't free. Although he has some online information at
http://www.baseprogramming.com/resources.html
Then you will need an object inspection tool such as XRAY or MRI. You only need one, I use MRI but there are many others using XRAY.
http://bernard.marcelly.perso.sfr.fr/index2.html
http://extensions.services.openoffice.o ... ction-tool

For a direct answer to your question I have included 2 macros. To use the first one from the menu at the top of your Form select Tools->Macro->Run Macro from there you will need to find where you stored it, and of course select Macro1.

Code: Select all

REM  *****  BASIC  *****

Sub Macro1
Dim x as string
Dim oDoc as object

oDoc = ThisComponent
x =  oDoc.CurrentController.Model.DrawPage.Forms.getByName("Form").getByName("Text Box 1").string
msgbox x
End Sub

Sub Macro2(oEvent as object)
Dim x as string

x= oEvent.source.Text
msgbox x
end sub
Macro 2 works when invoked by a Control Event for “Text Box 1” maybe “When losing focus” or “Changed”.
But
to re-write this name several times along the document
will require a you to do a good deal more learning.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
magalhaes88
Posts: 4
Joined: Thu Jul 14, 2016 2:13 am

Re: Macro copying a textbox

Post by magalhaes88 »

O. M. G. !
I was trully far away from my objective.

Another noob question:

The simple macro I wrote worked on MS Word 2010.
Is the diference from MS office to open Office that big?

thanks again
OpenOffice 3.1 on Windows 7
magalhaes88
Posts: 4
Joined: Thu Jul 14, 2016 2:13 am

Re: Macro copying a textbox

Post by magalhaes88 »

UnklDonald418 wrote: If there is a way to avoid using a Macro and there often is, then that is the way to go because writing Macros has a steep learning curve.

Do you know where I can find these shortcuts?

I have the impression that what I need is not a macro, but I don't knwo what it is or where to find. And, I'm not trying to be lazy here,but I'm searching for this "shortcut" for almost a month.


Thanks again
OpenOffice 3.1 on Windows 7
FJCC
Moderator
Posts: 9563
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Macro copying a textbox

Post by FJCC »

magalhaes88 wrote: Another noob question:

The simple macro I wrote worked on MS Word 2010.
Is the diference from MS office to open Office that big?
Macros for OpenOffice and Microsoft Office are very different. You will not be able to transfer code from one program to the other.
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.
UnklDonald418
Volunteer
Posts: 1573
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Macro copying a textbox

Post by UnklDonald418 »

On the surface MS Office and Open Office look quite similar, but under the hood many of those similarities disappear.
Without more details about what you are trying to do it will be difficult to give you specific recommendations.
Have you looked at the tutorials available on this Forum? Maybe you can also find some help there. Click on “Board index” at the top of this page and the new page has a Tutorials link.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Villeroy
Volunteer
Posts: 31348
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro copying a textbox

Post by Villeroy »

magalhaes88 wrote:
UnklDonald418 wrote: If there is a way to avoid using a Macro and there often is, then that is the way to go because writing Macros has a steep learning curve.

Do you know where I can find these shortcuts?

I have the impression that what I need is not a macro, but I don't knwo what it is or where to find. And, I'm not trying to be lazy here,but I'm searching for this "shortcut" for almost a month.


Thanks again
UnklDonald418 informs you about a steep learning curve while you are looking for "shortcuts". Drop all that unproductive macro bullshit or stick to MS Excel forever.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
RoryOF
Moderator
Posts: 35097
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macro copying a textbox

Post by RoryOF »

Chaoter 14 of the OpenOffice Writer guide will tell you how to use Input fields in a document, where you enter the data once and it appears elsewhere; without use of any macro. The OO Writer 3.3 document should be helpful (I think the OO 4 document is not yet available).
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
Post Reply