Record macro problem

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
mitduffy
Posts: 2
Joined: Sun May 13, 2018 6:38 pm

Record macro problem

Post by mitduffy »

I am a newbie trying to learn how to Record a Macro
To get started I made up a simple practice problem, namely have a macro take a short list of numbers in one file and paste them in another file.
Here are the details.

In a file named “Stored numbers I have a short list of numbers.
I want the macro to copy the numbers in “Stored numbers numbers and paste them in a file named “Deposited numbers”

I realize I can do this without a macro, but I would like to learn how to do this with a macro.

The Recorded macro “Storednumbers” below does this fine on the first execution of the macro. The numbers in "Stored numbers" now appear in "Deposited numbers"

However if after a first execution of the macro, I go back and change the numbers in the file “Stored Numbers”and then rerun the macro the numbers in the file “Deposited numbers” are not the new number but remain the original numbers, unchanged.

That seems to suggest that during the second execution the macro did not find or use the modified “Stored numbers” file as the revised source for numbers to be copied and pasted in “Deposited numbers”.


sub Storednumbers
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:OpenFromCalc", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$G$2"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "ToPoint"
args4(0).Value = "$D$4"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args4())

Again appreciate anyhelp.
Open Office 5.4 on Windows 7
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Record macro problem

Post by John_Ha »

Welcome to the (wrong) forum.

You are probably best to search and post in the Macros and UNO API forum.

See [Tutorial] How to record a macro (and Regular Expressions). Andrew Pitoynak's Useful Macro Information for OpenOffice.org at http://www.pitonyak.org/oo.php is an excellent reference for macros.
However if after a first execution of the macro, I go back and change the numbers in the file “Stored Numbers”and then rerun the macro the numbers in the file “Deposited numbers” are not the new number but remain the original numbers, unchanged.
Did you save the file after making the changes? If not, the changes are only held in memory and the macro presumably reads the .odt file on disc which will not have been updated.

Showing that a problem has been solved helps others searching so, if your problem is now solved, please view your first post in this thread and click the Edit button (top right in the post) and add [Solved] in front of the subject.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Record macro problem

Post by UnklDonald418 »

Trying to modify a recorded macro is probably not the best place to begin learning macro coding, plus it is rarely a good idea to use a macro for something that can be accomplished by other means.
Be aware that the Macro Recorder is a keystroke recorder, any mouse usage between Record Macro and Stop Recording is not saved.

If you are interested in learning macro coding then begin by reading "OpenOffice.org Macros Explained" by Andrew Pitonyak available for download from the link John_Ha provided.
You will also need an object inspection tool such as MRI
[Tutorial] Introduction into object inspection with MRI
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
Post Reply