locked
opening excel file from excel Add In RRS feed

  • Question

  • Hi,

       I am trying to open the excel file from my excel add in but it is not opening up. However the other documents such as pdf and word files are opening up. I am using the following code:

     ProcessStartInfo startInfo = new ProcessStartInfo();
     startInfo.FileName = fullFilePath;

     startInfo.ErrorDialog = true;
     Process.Start(startInfo);

    Is it possible to open the excel file with this code, (Without providing the excel.exe path)?

     

    Thanks,

    Sarabjit

     

     

    Tuesday, December 21, 2010 2:51 PM

Answers

  • Hi Sara,

     

    Because haven’t got your post back, I would like to give you a sample:

     

    private void button1_Click(object sender, EventArgs e)

            {

                Process MyProcess = new Process();

                ProcessStartInfo startInfo = new ProcessStartInfo();

                startInfo.FileName = @"C:\Test.xlsx";//Your Excel File Path

                startInfo.ErrorDialog = true;

                MyProcess.StartInfo = startInfo;

                MyProcess.Start();

                Thread.Sleep(1000);

                MyProcess.Dispose();

                GC.Collect();

            }

    Hope this can help you resolve your problem.

     

    Best regards,

    Paul Zhou


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Tuesday, December 28, 2010 6:17 AM
    Tuesday, December 28, 2010 6:17 AM

All replies

  • Hi Sara,

     

    Welcome to MSDN Forum!

     

    I have tried to use your code to open an excel file, and it ran perfect. I would like to get more description of your problem such as some error message. Have you set a break point to see which step the code didn’t run in.

     

    I look forward to hearing from you.

     

    Best regards,

    Paul Zhou


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 24, 2010 2:33 AM
  • Hi Sara,

     

    Because haven’t got your post back, I would like to give you a sample:

     

    private void button1_Click(object sender, EventArgs e)

            {

                Process MyProcess = new Process();

                ProcessStartInfo startInfo = new ProcessStartInfo();

                startInfo.FileName = @"C:\Test.xlsx";//Your Excel File Path

                startInfo.ErrorDialog = true;

                MyProcess.StartInfo = startInfo;

                MyProcess.Start();

                Thread.Sleep(1000);

                MyProcess.Dispose();

                GC.Collect();

            }

    Hope this can help you resolve your problem.

     

    Best regards,

    Paul Zhou


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Tuesday, December 28, 2010 6:17 AM
    Tuesday, December 28, 2010 6:17 AM