none
How to run macros from personal.xlsb

    Question

  • 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

    Monday, April 16, 2012 10:11 AM

Answers

  • 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

    Thursday, April 19, 2012 2:35 AM
    Moderator

All replies

  • 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.

    Monday, April 16, 2012 11:23 AM
  • 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

    Thursday, April 19, 2012 2:35 AM
    Moderator