I tried to create a simple macro to run a “Goal Seek” (same as “Tools” → “Goal Seek…”).
Let’s assume the following situation:
- Formula cell is A1
- Target value is in A2
- Variable cell is A3
I recorded a macro that contains the following code:
REM ***** BASIC *****
sub Goalseek
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:GoalSeekDialog", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoalSeek", "", 0, Array())
end sub
Unfortunately, nothing happens if I run the macro by hand. How can I adopt it to the upper cell names and make it work?