Yanıt How to run macros from personal.xlsb

  • 16 Nisan 2012 Pazartesi 10:11
     
      Kod İçerir

    Hi all,

    Hi all

    How to run the macros in excel from  personal.xlsb folder. Here is my code. But the code is not working. Please help

    With thanks

    Pol

    Excel.Application ExcelObj = null;
               ExcelObj = new Excel.Application();
               ExcelObj.Visible=true;
               Excel.Workbooks books = ExcelObj.Workbooks;
               Excel.Workbook sheet = books.Open(@"c:\Excel\PriceList1.xls");
    ExcelObj.Run("PERSONAL.XLSB!AdjustColumn");


    polachan

Tüm Yanıtlar

  • 16 Nisan 2012 Pazartesi 11:23
     
     
    Why would you expect an answer in a C# forum? Maybe an Office or Excel forum is the place to look?

    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

  • 19 Nisan 2012 Perşembe 02:35
    Moderatör
     
     Yanıt Kod İçerir

    Hi Pol,

    Welcome to the MSDN forum!

    We have to specify the location of the PERSONAL.XLSB file, and enclose it with apostrophe. Please try the following statement:

                 Excel.Workbook oWorkbook = oApp.Workbooks.Open("E:\\Test\\Test.xlsm");                       
                oApp.Run(@"'C:\Users\User\AppData\Roaming\Microsoft\Excel\XLSTART\PERSONAL.XLSB'!TestMsg");

    Note: You need to replace the path with the actual environment.

    Thanks.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us