![]() |
Button in Excel per Delphi drücken
Ich habe in Excel einen CommandButton (aus der Symbolleiste Steuerelemente). Dieser führt ein Makro bei Click aus. Ich schaffe es aber von Delphi aus nicht, einen Klick auf diesen Button zu simulieren oder das Makro auszuführen. Beim Button weiß ich nicht, wie das geht, beim Makro bekomme ich immer den Fehler: "Makro nicht gefunden" obwohl der Name stimmt. Hat jemand eine Idee was ich falsch mache? :gruebel:
|
Re: Button in Excel per Delphi drücken
Hallo,
ich muss zugeben, ich habe selten mit Excel gearbeitet, daher weis ich nicht, wie im einzelnen die Buttons angeordnet bzw. benannt sind, aber grundsätzlich sollte es gehen, dass du dir mit ![]() ![]() ![]() ![]()
Delphi-Quellcode:
Wie man ein Makro startet weis ich leider auch nicht.
PostMessage(ButtonHandle, BM_CLICK, 0, 0);
Gruß Mazel |
Re: Button in Excel per Delphi drücken
Zitat:
|
Re: Button in Excel per Delphi drücken
Ein Macro in Excel über den Umweg eines Button zu starten ist natürlich Käse.
Man kann direkt das Excel Application Objekt über Automatisierung anziehen und dann die Methode Run() aufrufen.
Code:
[id(0x00000103), helpcontext(0x00010103)]
HRESULT Run( [in, optional] VARIANT Macro, [in, optional] VARIANT Arg1, [in, optional] VARIANT Arg2, [in, optional] VARIANT Arg3, [in, optional] VARIANT Arg4, [in, optional] VARIANT Arg5, [in, optional] VARIANT Arg6, [in, optional] VARIANT Arg7, [in, optional] VARIANT Arg8, [in, optional] VARIANT Arg9, [in, optional] VARIANT Arg10, [in, optional] VARIANT Arg11, [in, optional] VARIANT Arg12, [in, optional] VARIANT Arg13, [in, optional] VARIANT Arg14, [in, optional] VARIANT Arg15, [in, optional] VARIANT Arg16, [in, optional] VARIANT Arg17, [in, optional] VARIANT Arg18, [in, optional] VARIANT Arg19, [in, optional] VARIANT Arg20, [in, optional] VARIANT Arg21, [in, optional] VARIANT Arg22, [in, optional] VARIANT Arg23, [in, optional] VARIANT Arg24, [in, optional] VARIANT Arg25, [in, optional] VARIANT Arg26, [in, optional] VARIANT Arg27, [in, optional] VARIANT Arg28, [in, optional] VARIANT Arg29, [in, optional] VARIANT Arg30, [out, retval] VARIANT* RHS);
Delphi-Quellcode:
var
objXL, MacroResult : OleVariant; begin objXL := CreateOleObject('Excel.Application'); objXL.Visible := True // Open the Workbook objXL.Workbooks.Open('C:\Statistik.XLS'); MacroResult := objXL.Run('MeinMacro', 0); // 0 ist ein Übergabeparameter, max 30 Stück möglich end; |
Re: Button in Excel per Delphi drücken
@shmia: wenn man weis wie, ist es natürlich so besser. :wink:
|
Re: Button in Excel per Delphi drücken
Alles klar. Weil ich zwei Makros mit dem selben Namen in verschiedenen Tabellenblätter hatte, musste ich noch "Tabelle1." vor den Makronamen setzen und das Makro wurde automatisch als "Private" gekennzeichnet. Das muss man auch noch entfernen, dann klappt das mit dem Run(..) wunderbar. Danke für die Tipps
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:05 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz