Record macro problem

Creating a macro - Writing a Script - Using the API

Record macro problem

Postby mitduffy » Sun May 13, 2018 11:48 pm

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
mitduffy
 
Posts: 2
Joined: Sun May 13, 2018 6:38 pm

Re: Record macro problem

Postby John_Ha » Mon May 14, 2018 2:59 am

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.
AOO 4.1.5, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 5850
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Record macro problem

Postby UnklDonald418 » Mon May 14, 2018 4:57 am

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.5 & LibreOffice 6.1.1.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 968
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 13 guests