Page 1 of 1

Record macro problem

PostPosted: Sun May 13, 2018 11:48 pm
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.

Re: Record macro problem

PostPosted: Mon May 14, 2018 2:59 am
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.

Re: Record macro problem

PostPosted: Mon May 14, 2018 4:57 am
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