Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi auf Excel VBA Variablen zugreifen (https://www.delphipraxis.net/58818-auf-excel-vba-variablen-zugreifen.html)

pittipivi 14. Dez 2005 17:10

Re: auf Excel VBA Variablen zugreifen
 
Hallo mumu,
hier mein Testcode. Vor allem der Bereich, der Excel aufruft, wie Du sagtest. Ich programmiere mit Delphi 7.


Delphi-Quellcode:
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Beenden1: TMenuItem;
    PageControl1: TPageControl;
    Button1: TButton;
    Button2: TButton;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    StringGrid1: TStringGrid;
    OleContainer1: TOleContainer;
    Button3: TButton;
    ExcelChart1: TExcelChart;
    ExcelWorksheet1: TExcelWorksheet;
    ExcelWorkbook1: TExcelWorkbook;
    ExcelApplication1: TExcelApplication;
....
procedure TForm1.Button1Click(Sender: TObject);
begin
 ExcelApplication1.Connect;
  ExcelApplication1.Visible[GetUserDefaultLCID] := False;
  ExcelApplication1.UserControl := True;
  ExcelApplication1.Workbooks.Open('D:\OLEBeispiel.xls',EmptyParam,EmptyParam,EmptyParam,
  EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
  EmptyParam,EmptyParam,EmptyParam,0);

  ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveWorkBook);

  ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets.Item['Interface'] as _Worksheet);
  ExcelWorksheet1.Activate;

  ExcelWorksheet2.ConnectTo(ExcelWorkbook1.Sheets.Item[2] as _Worksheet);
  ExcelWorksheet2.Activate;

  ExcelWorksheet3.ConnectTo(ExcelWorkbook1.Sheets.Item[3] as _Worksheet);
  ExcelWorksheet4.ConnectTo(ExcelWorkbook1.Sheets.Item[4] as _Worksheet);
end;
Zur Zeit teste ich vieles aus. Die Frage ist eben: Wie kann ich von Delphi7 aus auf Variablen und Konstanten in z.B. Modul1 von VBA zugreifen.
Gruß...
Peter

[edit=sakura] [delphi]Tags Mfg, sakura[/edit]

mumu 15. Dez 2005 06:51

Re: auf Excel VBA Variablen zugreifen
 
also normalerweise müsste es so in der richtung gehen:

Delphi-Quellcode:
uses VBIDE97; // or VBIDE_TLB

var CM          : CodeModule;
    i           : integer;
    current_line : string;
begin
  // Wenn du den VBA-Code von einer Arbeitsmappe auslesen/verändern willst
  // CM := ExcelWorkbook1.VBProject.VBComponents.Item(ExcelWorksheet1.Name).Codemodule;
  CM := ExcelWorkbook1.VBProject.VBComponents.Item('module1').Codemodule;

  // hier gehst du jetzt alle zeilen den Codemoduls durch
  for i:=0 to CM.CountOfLines-1 do
  begin
    current_line := CM.Lines[i];
    // In current_line befindet sich die aktuelle zeile
    // ...
  end;
end

mumu 23. Jan 2006 12:36

Re: auf Excel VBA Variablen zugreifen
 
hats jetzt eigentlich funktioniert?


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:49 Uhr.
Seite 2 von 2     12   

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