Seite 1 von 1

Makro für Calc

Verfasst: Di, 24.03.2015 11:32
von plutoluene22
Hallo Leute, habe in Calc folgendes Makro aufgezeichnet:
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"
args1(0).Value = "=E10*F10"

dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args1())


end sub

Das Makro funktioniert auch, aber leider wird =E10*F10 immer ausgeführt, auch wenn in z.B. in Zelle G15 befinde. Das Makro soll aber immer die beiden Zellen links neben der Zelle multiplizieren, in der ich mich befinde.

Re: Makro für Calc

Verfasst: Di, 24.03.2015 13:55
von Stephan
Das Folgende ist nicht sehr elegant programmiert, sollte aber funktionieren:

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

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
'---------------------------------
args1(0).Value = tmp_txt

dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args1())

end sub

Gruß
Stephan

Re: Makro für Calc

Verfasst: Di, 24.03.2015 16:28
von mikeleb
Hallo,

warum machst du die Frage noch einmal auf?

siehe: viewtopic.php?f=18&t=65462&p=253699#p253699

Re: Makro für Calc

Verfasst: Di, 24.03.2015 16:47
von plutoluene22
Hallo Stephan, Makro funktioniert prima, vielen Dank. Habe Makro für Plus, Minus,Dividieren selbst ändern können. Könntest Du mir noch die Änderung statt Produkt für *% und -% durchgeben. Dann wäre ich Dir sehr dankbar.
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. Genauso statt plus mit Minus
Gruß plutoluene22

Re: Makro für Calc

Verfasst: Di, 24.03.2015 16:50
von plutoluene22
Hallo mikeleb, habe die Frage in abgewandelter Form nochmals gestellt, da sie bei der ersten Frage nicht beantwortet wurde bzw. nicht funktioniert hat.
Gruß
plutoluene22

Re: Makro für Calc

Verfasst: Di, 24.03.2015 17:23
von mikeleb
Hallo,

clag hatte dir ein umfangreiches Tool geschrieben, das sehr gut funktioniert und dann war ohne weitere Erklärung irgendwie alles falsch ...

Re: Makro für Calc

Verfasst: Di, 24.03.2015 17:43
von plutoluene22
Sorry mikeleb, hatte das Tool von clag ausprobiert, bin aber nicht mit klargekommen, daher jetzt die 2. Anfrage mit der ich wunderbar klarkomme.
Gruß plutoluene22

Re: Makro für Calc

Verfasst: Di, 24.03.2015 21:45
von Stephan
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

Re: Makro für Calc

Verfasst: Mi, 25.03.2015 07:41
von plutoluene22
Hallo Stepfan,
vielen, vielen Dank, funktioniert alles wunderbar.
Gruß plutoluene22

Re: Makro für Calc

Verfasst: Mi, 25.03.2015 08:32
von plutoluene22
Hallo Stepfan, da Du mir so schön geholfen hast, hier noch eine Frage.
Ich hatte in Excel ein Makro, mit dem ich eine bestimmte Tabelle ( hier "Lotto")öffnen konnte:

Sub Lotto()

Workbooks.Open Filename:="D:\Eigene Dateien\Kalkulationen\Lotto neu.xls", UpdateLinks:=False

End Sub

Wie heißt das Ganze in Calc.
Habe schon alles durchsucht und nichts passendes gefunden.
Gruß plutoluene22

Re: Makro für Calc

Verfasst: Mi, 25.03.2015 09:33
von hylli
Ich kenne mich mit Makros leider nicht aus, aber Google-Suche nach "OpenOffice Makro Datei öffnen" findet diverse Infos, z.B.:
https://wiki.openoffice.org/wiki/DE/Mak ... C3.B6ffnen

Hylli

Re: Makro für Calc

Verfasst: Mi, 25.03.2015 09:41
von mikeleb
Hallo,
Habe schon alles durchsucht und nichts passendes gefunden.
Alles ist ziemlich viel ...

http://www.dannenhoefer.de/faqstarbasic ... ffnen.html

Re: Makro für Calc

Verfasst: Mi, 25.03.2015 09:41
von Jörg
Hallo,
also wenn es nur um das Öffnen der Tabelle aus einer anderen Tabelle heraus ist,
dann versuch mal Menü Einfügen->Hyperlink.
Dann brauchst Du kein Makro.

Gruß Jörg

Re: Makro für Calc

Verfasst: Fr, 27.03.2015 09:51
von plutoluene22
Hallo mikeleb , dein Hinweis auf Dannenhoefer hat mir geholfen.
Vielen Dank
plutoluene22