Record macro problem
Posted: 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.
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.