[Solved] Macros don't seem to know the current cell
Posted: Sun Jul 27, 2008 3:03 pm
I've recorded a macro that puts "Now" into the current cell and tied it to a hot-key.
When I hit the macro hot-key and quickly move to the next cell, then the macro result gets pasted into the next cell, not the cell that was active when I hit the hot-key. This works as I would expect in Excel (i.e. the macro remembers the active cell when it was invoked) and pastes the result into that cell and not the cell that just happens to be active at the time that it gets around to doing the pasting.
The macro that was produced by the recorder seems very complex for what I want it to do. Is there an easier macro that will work as I want? In any case, is it a bug that the macro does not remember the cell that was active when it was created?
Thanks,
Dan
The macro that was created by the recorder (somewhat top-heavy for the simple task):
When I hit the macro hot-key and quickly move to the next cell, then the macro result gets pasted into the next cell, not the cell that was active when I hit the hot-key. This works as I would expect in Excel (i.e. the macro remembers the active cell when it was invoked) and pastes the result into that cell and not the cell that just happens to be active at the time that it gets around to doing the pasting.
The macro that was produced by the recorder seems very complex for what I want it to do. Is there an easier macro that will work as I want? In any case, is it a bug that the macro does not remember the cell that was active when it was created?
Thanks,
Dan
The macro that was created by the recorder (somewhat top-heavy for the simple task):
Code: Select all
REM ***** BASIC *****
Sub Main
End Sub
sub InsertNow
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 ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Calculate", "", 0, Array())
rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "StringName"
Dim k as string
k = now
args2(0).Value = Str(Now)
dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args2())
rem ----------------------------------------------------------------------
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "By"
args3(0).Value = 1
args3(1).Name = "Sel"
args3(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args3())
rem ----------------------------------------------------------------------
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "By"
args4(0).Value = 1
args4(1).Name = "Sel"
args4(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args4())
end sub