Late binding - Automation von laufendem Excel
-
Hallo @all,
ich habe das folgende Problem. Ich möchte gerne ein Makro unter Excel ausführen, unabhängig davon, welche Excel-Version genutzt wird.
Eine lange Suche in google hat mich dazu geführt, dass ich late binding einsetzten muss, um versionsunabhängig automatisieren zu können.
Early binding code der funktioniert:
Microsoft.Office.Interop.Excel.Application XL = null; XL = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); foreach ( Excel.Workbook _wb in XL.Workbooks ) { System.Windows.Forms.MessageBox.Show(_wb.Name.ToString()); }
Wie setze ich das ganze jetzt mit late binding um?
Mein Versuch:
object objApp_Late; object objBook_Late; Type objClassType; objClassType = Type.GetTypeFromProgID("Excel.Application");
Das Ergebnis des Typs ist "Microsoft.Office.Interop.Excel.ApplicationClass"
Wie kann ich jetzt die laufenden Excel-Instanzen enumerieren und die darin geöffneten Workbooks durchlaufen?
-
-
Mein Tip: Verwende für sowas Visual Basic mit 'Option Strict Off', es ist einfach besser dafür geeignet.