# Revision history [back]

Hello,

Seems to me you don't need any buttons at all.

The macro can be attached to a toolbar item. The value to be used would come from the selected cell. Select wanted cell & press the Toolbar item and use that value in the macro:

Sub UseSelected
Dim oCurrentelection as Object
Dim sString              as String
Dim nValue              as Double
oCurrentSelection = ThisComponent.getCurrentSelection()
Rem selection depending upon what you may be doing
sString = oCurrentSelection.getString()
nValue = oCurrentSelection.getValue()
Print sString
Print nValue
End Sub


Hello,

Seems to me you don't need any buttons at all.

The macro can be attached to a toolbar item. The value to be used would come from the selected cell. Select wanted cell & press the Toolbar item and use that value in the macro:

Sub UseSelected
Dim oCurrentelection as Object
Dim sString              as String
Dim nValue              as Double
oCurrentSelection = ThisComponent.getCurrentSelection()
Rem selection depending upon what you may be doing
sString = oCurrentSelection.getString()
nValue = oCurrentSelection.getValue()
Print sString
Print nValue
End Sub


Edit:

This is not a copy/paste as you asked for. My comment explained the reason. Each control must have a unique internal name and must be anchored to the cell immediately left of the data on the same line:

Sub UseSelected(oEvent)
Dim oSheet             as Object
Dim oDrawPage          as Object
Dim oItem              as Object
Dim oControl           as Object
Dim oValueCell         as Object
Dim sName              as String
Dim sControlName       as String
Dim nCount             as Integer
Dim x                  as Integer
Dim nColumn            as Double
Dim nRow               as Double
Rem - Get control name
sName = oEvent.Source.Model.Name
oSheet=ThisComponent.CurrentController.ActiveSheet
oDrawPage = oSheet.getDrawPage()
nCount = oDrawPage.getCount()
Rem - Search for control name on draw page
For x = 0 to nCount-1
oItem = oDrawPage.getByIndex(x)
oControl = oItem.getControl()
sControlName = oControl.Name
If sName = sControlName Then exit For       Rem Control found
Next x
Rem - Get anchored cell address
Rem - Get data from cell one column to right
oValueCell = oSheet.getCellByPosition(nColumn+1, nRow)
Print oValueCell.String
End Sub