![]() |
Word Makro mit OleVariant erstellen
Hallo liebe Delphi-Praxis-Gemeinde!
Mal wieder plage ich mich seit tagen mit einem Bösen Problem herum...ich möchte per OLE mit einem OleVariant ein Makro in Word zur Laufzeit erstellen. Dazu habe ich schon Code gefunden und bis hierher umgesetzt:
Delphi-Quellcode:
Jetzt habe ich folgendes Problem : [DCC Fehler] Unit1.pas(44): E2010 Inkompatible Typen: '_VBComponent' und 'Variant'
uses VBIDE_TLB;
Procedure Tform1.CreateMakroInWord; var NewMakro : _VBComponent; begin If FindWindow(nil,pchar('Dokument1 - Microsoft Word'))=0 then begin try wordapp:=CreateOleObject('Word.Application'); except ShowMessage('WORD konnte nicht gestartet werden !'); Exit; end; Wordapp.documents.add; end else begin try wordapp:=GetActiveOleObject('Word.Application'); except ShowMessage('WORD konnte nicht gefunden werden !'); Exit; end; end; Wordapp.visible:=true; Wordapp.activedocument.VBProject.Name := 'MyProject'; NewMakro:=Wordapp.activedocument.VBProject.VBComponents.Add(1); //Hier liegt das Problem NewMakro.CodeModule.InsertLines(1, 'Public Sub '+#13+'msgbox "TEST"'+#13+'End Sub'); Wordapp.activedocument.activate; end; das heißt er kann das ganze nicht als Olevariant anfahren, da es sich bei "NewMakro" um eine _VBComponent handelt...ich weiß nicht wie ich das ganze lösen kann. Hiiilfeeee :wink: ? Vielen Dank im voraus!!! greez gabneo :dp: EDIT Wenn ich es wie folgt kompiliere gibt Word folgende Message aus: "Dem programmatischen Zugriff auf das Visual Basic-Projekt wird nicht vertraut."
Delphi-Quellcode:
Procedure Tform1.CreateMakroInWord;
begin If FindWindow(nil,pchar('Dokument1 - Microsoft Word'))=0 then begin try wordapp:=CreateOleObject('Word.Application'); except ShowMessage('WORD konnte nicht gestartet werden !'); Exit; end; Wordapp.documents.add; end else begin try wordapp:=GetActiveOleObject('Word.Application'); except ShowMessage('WORD konnte nicht gefunden werden !'); Exit; end; end; Wordapp.visible:=true; Wordapp.activedocument.VBProject.Name := 'MyProject'; Wordapp.activedocument.VBProject.VBComponents.Add(1); Wordapp.activedocument.VBProject.VBComponents.items(1).CodeModule.InsertLines(1, 'Public Sub '+#13+'msgbox "TEST"'+#13+'End Sub'); Wordapp.activedocument.activate; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:13 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