Makro Laden

SiriuS1337

Grünschnabel
Servus zusammen,

weiß einer wie ich aus .Net ein Makro in einem Excel file laden kann ? Hab schon gegoogelt aber wirklich Hilfreich war da nix.. die Excel.dll hab ich bereits bei den Referenzen eingebunden.


danke im voraus !
 
hi, danke erstmal für die schnelle Antwort !

Ich brauch das ganze zwar für VB .Net aber maybe bekomm ich ja ne Idee aus dem c# Zeugs.

Danke !
 
Der wichtige Part wird wohl
Code:
private void RunMacro(object oApp, object[] oRunArgs)
{
    oApp.GetType().InvokeMember("Run",
        System.Reflection.BindingFlags.Default |
        System.Reflection.BindingFlags.InvokeMethod,
        null, oApp, oRunArgs);
}
sein. Das nach VB.NET zu transferieren sollte nicht das Problem darstellen. Möglichkeiten dies zu vereinfachen wurden in letzter Zeit immer wieder im Forum gepostet.
 
hi danke nochmal ! funktiobniert mit folgendem:

Code:
 Dim oExcel As Excel.ApplicationClass
        Dim oBook As Excel.WorkbookClass
        Dim oBooks As Excel.Workbooks

        'Start Excel and open the workbook.
        oExcel = DirectCast(CreateObject("Excel.Application"), Excel.ApplicationClass)
        oExcel.Visible = True
        oBooks = oExcel.Workbooks
        oBook = DirectCast(oBooks.Open("c:\template.xls"), Excel.WorkbookClass)

        'Run the macros.
        oExcel.Run("prcTest")
        
        'Clean-up: Close the workbook and quit Excel.
        oBook.Close(False)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
        oBook = Nothing
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
        oBooks = Nothing
        oExcel.Quit()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
        oExcel = Nothing

http://support.microsoft.com/kb/306682/EN-US/

ich muss nur noch rausbekommen wie ich von dem makro einen rückgabe wert an .Net schicken kann...
 
Zurück