I need how to assign cell values to variables with macros

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

Hello,

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.

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?

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.

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