von Stephan » Di, 24.03.2015 21:45
Ich befinde mich z. B. in Zelle H15, in Zelle F15 steht 100, in Zelle G15 steht 10%, dann soll das Makro =F15+F15*G15 rechnen, so dass 110 rauskommt.
Code: Alles auswählen
sub Produkt
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 = "StringName"
'---------------------------------
tmp_txt = ""
tmp = ThisComponent.getCurrentSelection
x = tmp.RangeAddress
x_col = x.StartColumn
x_row = x.StartRow
If Right(ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-1, x_row).FormulaLocal, 1) = "%" Then
xx = ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-2, x_row)
xxa = Split(xx.AbsoluteName, ".")
xxb = Split(xxa(1), "$")
xxc = Join(xxb(),"")
tmp_txt = "=" & xxc & "+(" & xxc & "*"
xx = ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-1, x_row)
xxa = Split(xx.AbsoluteName, ".")
xxb = Split(xxa(1), "$")
xxc = Join(xxb(),"")
tmp_txt = tmp_txt & xxc & ")"
Else
xx = ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-2, x_row)
xxa = Split(xx.AbsoluteName, ".")
xxb = Split(xxa(1), "$")
xxc = Join(xxb(),"")
tmp_txt = "=" & xxc & "*"
xx = ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-1, x_row)
xxa = Split(xx.AbsoluteName, ".")
xxb = Split(xxa(1), "$")
xxc = Join(xxb(),"")
tmp_txt = tmp_txt & xxc
End If
'---------------------------------
args1(0).Value = tmp_txt
dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args1())
end sub
[quote]Ich befinde mich z. B. in Zelle H15, in Zelle F15 steht 100, in Zelle G15 steht 10%, dann soll das Makro =F15+F15*G15 rechnen, so dass 110 rauskommt.[/quote]
[code]sub Produkt
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 = "StringName"
'---------------------------------
tmp_txt = ""
tmp = ThisComponent.getCurrentSelection
x = tmp.RangeAddress
x_col = x.StartColumn
x_row = x.StartRow
If Right(ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-1, x_row).FormulaLocal, 1) = "%" Then
xx = ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-2, x_row)
xxa = Split(xx.AbsoluteName, ".")
xxb = Split(xxa(1), "$")
xxc = Join(xxb(),"")
tmp_txt = "=" & xxc & "+(" & xxc & "*"
xx = ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-1, x_row)
xxa = Split(xx.AbsoluteName, ".")
xxb = Split(xxa(1), "$")
xxc = Join(xxb(),"")
tmp_txt = tmp_txt & xxc & ")"
Else
xx = ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-2, x_row)
xxa = Split(xx.AbsoluteName, ".")
xxb = Split(xxa(1), "$")
xxc = Join(xxb(),"")
tmp_txt = "=" & xxc & "*"
xx = ThisComponent.CurrentController.ActiveSheet.getCellbyPosition(x_col-1, x_row)
xxa = Split(xx.AbsoluteName, ".")
xxb = Split(xxa(1), "$")
xxc = Join(xxb(),"")
tmp_txt = tmp_txt & xxc
End If
'---------------------------------
args1(0).Value = tmp_txt
dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args1())
end sub[/code]