I’m a NOOB at writing macros in Calc. I’ve been recording macros and then modifying them. I am creating a baseball game based on Cadeco All-Star baseball. I have a working version that requires opening one spreadsheet for each team. What I’m trying to do is create one where both teams are displayed on one spreadsheet. The game requires a random number to generate the batting results. Works great if there is one spreadsheet open for each team.
In the version I am trying to create, I need to have a macro that generates the random number for just one team and then writes it to a cell. So, I recorded a macro to move to specific cell and then enters a value into that cell.
Below is the macro with a section labeled CODE THAT I ADDED. It generates the random number. What I need assistance with is changing the section labeled THE PART THAT NEED TO BE CHANGED so that iVar will be written to current cell.
I am running version 7.3.7.2 under Linux Mint 21.2.
Any assistance will be appreciated.
sub HomeRoll
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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = “ToPoint”
args1(0).Value = “$O$3”
dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args1())
rem ----------- CODE THAT I ADDED ----------------------------------
Dim iVar As Integer
iVar = Int((360 * Rnd) -1)
Print iVar
rem ----------- THE PART THAT NEEDS TO BE CHANGED ------------------
rem ----------- need to write iVar to the current cell ------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = “StringName”
args2(0).Value = “1234”
dispatcher.executeDispatch(document, “.uno:EnterString”, “”, 0, args2())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, “.uno:JumpToNextCell”, “”, 0, Array())
rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = “ToPoint”
args4(0).Value = “$A$1”
dispatcher.executeDispatch(document, “.uno:GoToCell”, “”, 0, args4())
end sub