none
IN VB.NET Excel Reading and Writing Application Issue

    Question

  • In our VB.Net application, we are performing read/write operations on Excel.
    While running the application, if we try to open other excel file(s) manually then
     - the application is throwing an exception,
     - the other excel file is closed automatically and
     - the application is also closed automatically.
    • Moved by Cindy Meister MVPMVP Wednesday, December 12, 2012 4:56 PM not using VSTO technology (From:Visual Studio Tools for Office)
    Wednesday, December 12, 2012 2:02 PM

Answers

  • Hi Bandaru55555,

    It's based on my experience that Visual Studio 2010 has no PIA assembly to support Office 2003. I think it will work fine if you implement Native Office COM interface via C++. If you request must allow that, please feel free to let me know, I will involve some experts into your thread.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 2:45 AM
    Moderator

All replies

  • apparently you handle some events on excel object that fire when file is opened manually and you misbehave in those events handlers. try debugging that issue, add some try/catch blocks.
    Wednesday, December 12, 2012 2:28 PM
  • Hi DamianD,

    Thanks for gave answer from my question.

    Now I am getting "Exception from HRESULT: 0x800A01A8" Exception and

    to dispose  excel object i am using this code :

    private void releaseObject(object obj)
            {
                try
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                    obj = null;
                }
                catch (Exception ex)
                {
                    obj = null;
                }
                finally
                {
                    GC.Collect();
                }
            }

    at this function calling time the Manually open excel file closing. Please give solution for my problem this is urgent for me. If possible please give one sample application and give good reference links.

    Wednesday, December 12, 2012 3:23 PM
  • Hi Bandaru55555,

    thanks for posting in the MSDN Forum. I can't reproduce your issue under Office 2010, Visual Studio 2010 environment. I tried to open an exist spreadsheet document via program and open another manually after that. I can encounter the situation your mentioned. Would you please clarify your details for further research.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 13, 2012 5:33 AM
    Moderator
  • Hi DamianD,

    Thanks for gave answer from my question.

    this is the code I wrote in my application

    1. we are using Office 2003.

    For Excel Reading Function:=>

            public void serviceCall()
            {
                List<string> returnString = new List<string>();
                Application xlApp = new Application();
                Workbook xlWBook;
                Worksheet xlWSheet;
                Range xlRange;
                xlWBook = xlApp.Workbooks.Open(@"D:\temp.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlMacintosh, "\t",true , true , 0, true, "user", 0);
                    xlWSheet = (Worksheet)xlWBook.Worksheets.get_Item("Class & Config Profile");
                    xlRange = xlWSheet.UsedRange;
                    for (int r = 1; r <= xlRange.Rows.Count; r++)
                    {
                        for (int c = 1; c <= xlRange.Columns.Count; c++)
                       {
                        object value = (xlRange.Cells[r, 3] as Range).Value2;
                        returnString.Add(value == null ? "" : value.ToString());
                        writer.WriteLine(value == null ? "" : value.ToString());
                       }
                    }
                    releaseObject(xlWSheet);
                    releaseObject(xlWBook);
                    releaseObject(xlApp);
                    var t = returnString;
           }

    Excel Object Dispose Function ;=>

           private void releaseObject(object obj)
            {
                try
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                    obj = null;
                }
                catch (Exception ex)
                {
                    obj = null;
                }
                finally
                {
                    GC.Collect();
                }
            }

    Please resolve my issue.  I have very urgent product issue.

    Thursday, December 13, 2012 7:49 AM
  • Hi Bandaru55555,

    I notice that you mentioned:

    In our VB.Net application, we are performing read/write operations on Excel.

    In you post, and you explained your issue via C# at the last post. Do you mean that issue is not related to program language? I would recommend you clarify your Visual Studio version for further research.

    Have a goo day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 18, 2012 6:01 AM
    Moderator
  • Hi Tom,

    yes this issue not relating to PL. can u help me to resolve my problem. we are using VS2010 , .net, .NET 4.0 version and  MSOffice 2003. please help me.

    Tuesday, December 18, 2012 7:47 AM
  • Hi Bandaru55555,

    It's based on my experience that Visual Studio 2010 has no PIA assembly to support Office 2003. I think it will work fine if you implement Native Office COM interface via C++. If you request must allow that, please feel free to let me know, I will involve some experts into your thread.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 2:45 AM
    Moderator