Ask Your Question

I need how to assign cell values to variables with macros [closed]

asked 2018-10-31 18:21:35 +0100

Todd2 gravatar image

Hi All,

Would someone point me to an example or a how to that shows how to assign values in cell to variables in macros?

Many thanks, -T

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by erAck
close date 2018-11-03 19:42:26.576066

2 Answers

Sort by » oldest newest most voted

answered 2018-11-03 06:38:17 +0100

Todd2 gravatar image

I wrote myself a test

Sub GetCellValueTest
   Dim Sheet
   Dim D2
   Dim F5
   Dim C4
   Dim RtnCode As Integer

   rem assign a tab (sheet)
   Sheet = thiscomponent.sheets.getByName("Jump Log")

   rem get the position of "$D$2"
   D2 = Sheet.getCellRangeByName( "$D$2" )

   rem print oCell.value, oCell.string, oCell.formula, oCell.FormulaLocal, oCell.Error
   print D2.string, D2.value

   rem get the position of "$F$5"
   F5 = Sheet.getCellRangeByName("$F$5")

   rem write D2's string value to F5's position
   F5.setString( D2.string + " abc" )

   rem re-get "$F$2" after is hasw been overwritten
   F5 = Sheet.getCellRangeByName("$F$5")
   RtnCode = MsgBox( F5.string + "    ", 0, "Cell Value" )

   C4 =  Sheet.getCellRangeByName("$C$4")
   RtnCode = MsgBox( C4.string + "    ", 0, "Oh No!" )

End Sub
edit flag offensive delete link more

answered 2018-10-31 18:56:16 +0100

Ratslinger gravatar image


This and many questions regarding macros can be found in "Open Office Macros Explained" by Andrew Pitonyak. The PDF can be obtained here -> OOME. Chapter 15 deals with Calc.

edit flag offensive delete link more


Thank you!

Not to ask too stupid a question, but where in that manual does it tell me how to read a value from a cell?

Also, do I get the exact formatting of the text in the cell?

Todd2 gravatar imageTodd2 ( 2018-11-03 06:32:20 +0100 )edit

Section 15.2.2 with a sample in Listing 410. A multitude of examples and methods are described as the chapter go on. Don't exactly understand what '..exact formatting of the text...' means; things such as Bold or Italic? If that is the case, it is an entirely different issue.

Ratslinger gravatar imageRatslinger ( 2018-11-03 16:39:55 +0100 )edit

Question Tools

1 follower


Asked: 2018-10-31 18:21:35 +0100

Seen: 2,160 times

Last updated: Nov 03 '18