Home » MS Office

system.AccessViolationException when trying to open excel workbook

System.Exception: CriticalProgramError ---> System.Exception: CriticalProgramError ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)

2 Answers Found


Answer 1



Have you found the issue yet ?


I got the same problem today.


All my developpements works fine on Windows 2000 or XP with any Excel from 2002 to 2007.


But when i deploy this application on a Windows XP with Office 2000, i've got this Exception.


I think it's because of the Excel API i use (2002) but i'm not sure.


Answer 2

Hi Sreenatha

The error message, alone, won't give us enough information to help you, I fear.

Could you show us the code involved that triggers the message, please? Not just the line with Workbooks.Open, but everything to do with instantiating the Excel application.

Also, have you checked that Workbooks.Open is causing the error, or could it be some other line of code?

Is your code running in some kind of loop?

What kind of project is this (WinForms, Console App, etc.)?



Does anyone know of a program to automatically convert 2003 workbooks to 2010 workbooks?  In excel 2010 the conversion process requires opening the file answering a couple of prompts.  Then executing a macro I wrote to save the workbook in the current format.  The prompts are the problem.  I might use “SendKeys” to automatically answer the prompts, but if there is a program I would rather use it.   ups, SendKeys does not work!


Does anyone know of a program to automatically convert 2003 workbooks to 2010 workbooks?  In excel 2010 the conversion process requires opening the file answering a couple of prompts.  Then executing a macro I wrote to save the workbook in the current format.  The prompts are the problem.  I might use “SendKeys” to automatically answer the prompts, but if there is a program I would rather use it.



I have a Visual Studio 2010 Office Excel 2010/2007 project.  

When I compile the project, the Excel Workbook is made available with the DLL.  

I want to know if it is possible to have the relevant files that are generated in the compilation process embedded in the Excel 2007/2010 workbook that is being designed?

I want to do this as it will make life a lot easier being able to give my clients a single workbook with the compiled code embedded, rather than having them look after all of the separate files.


Thank you.

I have written some code that opens an Excel Workbook if it exists and activates a certain Worksheet if the parameter is met and the Worksheet exists. My question is once the Workbook is open if it is minimized or it is not the Application that has the focus what code can be used to check and see if the file is already open and if so, simply activate the Active Workbook and the Worksheet that is specified without opening a whole new Workbook? If you would like to see my code I can post it.
I have written some code that opens an Excel Workbook if it exists and activates a certain Worksheet if the parameter is met and the Worksheet exists. My question is once the Workbook is open if it is minimized or it is not the Application that has the focus what code can be used to check and see if the file is already open and if so, simply activate the Active Workbook and the Worksheet that is specified without opening a whole new Workbook? If you would like to see my code I can post it.

I am getting "This workbook is larger than the maximum workbook size allowed to be opened in the browser" even though I have configured the right settings as said here:



I created a simple 2007 workbook with a cell having formula. The formula contains a simple Lookup type INDEX function [  =INDEX(C7:D14,2,2)   ]. The excel workbook when opened in Excel 2007 is showing the data for this cell correctly. But when I tried to open the workbook using excel services 2007, I got an error like this “An error has occurred.If I am using formula with any other simple function (say SUM) then the excel service is opening the workbook without any error. I tried this many times and not sure why Excel Services 2007 does not support excel workbook with built in INDEX function.


I am not using any other user defined function in the workbook/formula. Please someone help me.



I am trying to transfer data from a VB form to an existing Excel 2003 file. This is the code I am using, but it is throwing up the following error:

NullReferenceException was Unhandled. in the line I have made bold.

I have coded in VBA but am new to VB.NET and am struggling with setting up the objects. Can anyone tell me where I have gone wrong please?



Dim oXL As Excel.Application


Dim oWB As Excel.Workbook


Dim oSheet As Excel.Worksheet


Dim oRng As Excel.Range, oRng1 As Excel.Range, oRng2 As Excel.Range


oXL = System.Diagnostics.Process.Start("C:\VBTest.xls")

oWB = oXL.Workbooks(


oSheet = oWB.Worksheets(



oRng = oSheet.Range("A2")

oRng1 = oSheet.Range(


oRng2 = oSheet.Range(


oRng.Value =


oRng1.Value =


oRng2.Value =


oWB =


oSheet =





hello and thanks for your time.

i am having issues with automating Excel from C# 2010.  i have multiple computers to deploy to, with multiple versions of office (single office installation per computer).  i have tried the office 2007 interop assemblies, and i have tried the office XP interop assemblies, and both will not open an existing XL file.  i can create a new XL file without error with each of the interop assemblies, but upon opening an exisitng file, my program crashes. here is the code i have tried with both 2007 and xp interop assemblies:


Microsoft.Office.Interop.Excel.ApplicationClass xl;

Microsoft.Office.Interop.Excel.Workbook wb;

xl = new Microsoft.Office.Interop.Excel.ApplicationClass();

OpenFileDialog fd = new OpenFileDialog();

if ( fd.ShowDialog() != System.Windows.Forms.DialogResult.Cancel) {

//i have tried this:

wb = xl.Workbooks.Open(Filename: @fd.FileName, ReadOnly: true);

//and this:

wb = xl.Workbooks.Open(@fd.FileName, 0, true, 5,"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true,1,0);

//and this:

wb = xl.Workbooks.Open(fd.FileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue);

//and this:

wb = xl.Workbooks.Open(fd.FileName);



Hello To you,


I am looking to open existing MS Excel workbook in internet explorer... 


I mean, my exact requirement is how can we open Excel workbook within browser with any web application.

I am looking something like Excel services in Share point 2010..

Please help me.




I have a little vbs script that instantiates the Excel.Application object and then opens a work book to perform some tasks on it. The script runs fine when run from the command line. When I attempt to run it as a scheduled task (it is supposed to update data that is pulled from a SQL Server at regular intervals), it fails with the following error:

Microsoft Office Excel cannot access the file 'c:\test\SampleWorkbook.xlsm'. There are several possible reasons: .....

The file does exist. The path reported in the error is correct. The account under which the task is running is the same account I use to run it from the command line. User Account Control is not enabled, and the task is set up to run with highest privileges. When I run the same script through the Task Scheduler from a Windows Server 2003 machine, it works without issue.

I was just wondering if somebody on this forum has run into a similar issue in connection with Windows Server 2008 R2 and figured out what the magic trick is to make it work. I'm sure it is rights related, but I haven't quite figured out what which rights are missing.

Thanks in advance for any advice you may have.



I've downloaded the trial version of Excel 2010 (Home and Student, version 14.0), and am trying to get some of my old Excel 2002 code to run. It is lengthy, but the pertinent bits are:


Dim ZeroBook As Object


   For Each Wb In Workbooks
    If Wb.Name = wName Then                'wName has been set properly elsewhere
    Set ZeroBook = Workbooks(wName)

    Application.DisplayAlerts = False
    Application.DisplayAlerts = True

When running the above code, it blows up on the statement ZeroBook.Save (or, at least, if I answer "Debug" to the error message "Method 'Save' of object '_Workbook' failed", it highlights that statement). I have confirmed in Debug that Workbook.name and workbook.path are as intended. Moreover, if I just press F8, the statement executes perfectly!


Workbooks(CurvesName).Activate              'CurvesName="Curves17.xls"

This statement is just ignored: the existing active workbook stays the same. It blows up a bit later, when it does not find the active workbook which it is expecting.

3. And finally, when getting all the info together for this message, I got the dreaded "Microsoft Excel has encountered a problem and needs to close.  We are sorry for the inconvenience" message! Twice! What a bummer! I would have thought that MS would have fixed this sort of thing by now. Why should I even bother with Excel 2010?

Any help or suggestions will be welcome. Else, I'll just have to stick with  Excel 2002, which, while not perfect, is at least a lot faster, and is the devil I know.


PS: I run a Dell Vostro 1710 with Windows XP Version 5.1 Service Pack 3.


Hi Apurva

   I am developeing an Excel Application.

   i get Data File Daily.

 Based on this data file i need to generate two reports.

approach i have taken:

   have Excel template which has two reports sheets [daily MIS] [OverView]

   Task pane offers selecting an excel file [data file].

   copy a sheet [Daily Dump] from Data file and paste it into the Excel file generate based on template

  so now new file has two sheets[daily MIS] [OverView] + i copied sheet [Daily Dump] .

   How to copy a worksheet of one workbook into the other workbook ?

i have been trying this long ....
not getting answer

private Excel.Worksheet xlWS= null;
xlWS holds reference to [Daily Dump] .[a file selected by user but whose visibility is set to false]

this.xlWS.Copy(missing, Globals.Sheet1.InnerObject);

nothing happens ........

can u guide me ......

nilesh shah


I am attempting to deploy an Excel workbook application, with a custom ribbon tab and action pane, written in VS 2010.  I am using a setup and deployment project in my solution, *not* Click Once deployment via the publish option of the project properties. 

I manually added the .vsto file to the application folder of the setup and deployment project and still I see this exception. 

Here is more information about the exception:

System.Deployment.Application.DeploymentDownloadException: Downloading file:///C:/Program Files (x86)/IIS/IIS Reporting Excel Interop/ExcelWorkbookEx1.dll.manifest did not succeed. ---> System.Net.WebException: Could not find file 'C:\Program Files (x86)\IIS\IIS Reporting Excel Interop\ExcelWorkbookEx1.dll.manifest'. ---> System.Net.WebException: Could not find file 'C:\Program Files (x86)\IIS\IIS Reporting Excel Interop\ExcelWorkbookEx1.dll.manifest'. ---> System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\IIS\IIS Reporting Excel Interop\ExcelWorkbookEx1.dll.manifest'.

Here are the files in the installation folder:

              12 File(s)        947,979 bytes

Thanks for any input, or thoughtful response!


Dear Gurus,

I am so frustrated with this very weird behavior. I am working on the Excel Services 2007. Once I successfully published an Excel spreadsheet and displayed it thru "view in the web browser" in MOSS 2007, the 2nd time I published it with a very small change, it didnt work. The above error message appeared.
I took the original file before doing change, and republished it. It still didnt work!
Then I tried to save/publish it with a different name, it didnt work!
Then I remember, I once published it and save it with the existing name (that ever worked) and worked!
But the other time when I republished it with this name (just curious with this very strange behavior), and it didnt work!
After that I created a very simple sheet with one named cell "Hello Word" then published it with whatever file name (replaced the existing, new name), and what? IT DIDN'T WORK!

I am very sure, it has nothing to do with the compatibility issue, because there were few times they worked. I already went thru the docs to check what Excel features that are not supported in web services.

Please someone help me. This is very annoying.
My apology if someone have ever posted this. But I could find any with a good and clear answer.

A Sharepoint newbie



I'm exporting some information to an Excel Workbook using SSIS.

But when i open the workbook all the 'number' cells are written as text.

this means the user first has to select all the numbers and click on the Convert to Number context menu item.

How I can export values as number from the beginning?



I have created a Workbook in Excel 2003. It is actually a tool which also has some VBA script code. When users try to open and use it in Excel 2007, the sheets start misbehaving. Some people are unable to open the file, while for some Excel 2007 crashes.

In some cases Excel 2007 does not crash, but the sheets dont work as expected.

My system info is (where I developed this sheet):

Windows XP Version 2002, Service Pack 2.





We have a requirement to create a Form as part of an excel add-in. The form will allow user to set a number of settings and save them with the excel file. The settings should also be visible to other part of the add-in code.

I did some search, and see that in Excel 2007, you can add a custom XML part to an Excel workbook. Unfortunately this is not available in Excel 2003.

Any suggestions?




I have created a document library as "BCM_Temporary_Folder" and in shared services Trusted File Location I have set the information as below.

Address: http://01hw158037:555/BCM_Temporary_Folder/

Location Type:Windows SharePoint Services
Trust Childred: True
Allow External Data: Trusted data connection libraries and embedded

and all other properties are set to default.

I am able to upload the file but when trying to read the workbook I am getting the above reader.



object[] GetExcelData(string targetWorkbookPath, String SheetName, string strColumns, string strIndexTo)


string siteurl = SPContext.Current.Site.RootWeb.Url;



Status[] outStatus;



string strIndexFrom = "1";



//string strIndexTo = "983";


//string strColumns = "5";


//string strSheetName = "USMAP Ver 6.0";


object[] AllExcelData = newobject[1000];






ExcelService xlservice = this.GetExcelService(siteurl);



string sessionId = xlservice.OpenWorkbook(targetWorkbookPath, "en-US", "en-US", out outStatus);



RangeCoordinates rng = newRangeCoordinates();



//rng.Row = Convert.ToInt32(strIndexFrom);


//rng.Column = 0;


//rng.Width = Convert.ToInt32(strColumns);


//rng.Height = Convert.ToInt32(strIndexTo);

rng.Row =




rng.Height =



AllExcelData = xlservice.GetRange(sessionId, SheetName, rng,


true, out outStatus);


catch (Exception ex)


JJCUS_GCM_CommonExceptionLogger.LogException(ex.Message + "--" + targetWorkbookPath, ex.StackTrace, JJCUS_GCM_UploadCSVConstants._strModuleNameMsg);


return AllExcelData;




In excel service setting: File Access Method = "Impersonation
". Other properties are set to default.

So is there anything I am missing:

1. Anything to do with the permissions of the Doc Library?

2. Anything wrong in setting the Trusted File Location"?

3. Anything wrong in share point Excel Service Setting

thanks in advance..







rng.Column = 0;

rng.Width =




Background: In order to automate and embed Excel in a windows form application I've used the webBrowser control.

I am able to navigate to the Excel file without a problem.To navigate I am using

this.WebBrowserExcel = new AxSHDocVw.AxWebBrowser
object oURL = "c:\Excel_Test.xls
this.WebBrowserExcel.Navigate2(ref oURL, ref oEmpty, ref oEmpty, ref oEmpty, ref oEmpty);

After navigating to the Excel file, I am querying the running Object table to attach to the workBook and then manipulate the cells in the workbook.

Microsoft.Office.Interop.Excel.Workbook eWorkBook eWorkBook = (Microsoft.Office.Interop.Excel.Workbook)GetActiveWorkbook(m_ExcelFileName)

public Workbook GetActiveWorkbook(string xlfile)
      IRunningObjectTable prot = null;
      IEnumMoniker pmonkenum = null;
        IntPtr pfetched = IntPtr.Zero;
        // Query the running object table (ROT)if (GetRunningObjectTable(0, out prot) != 0 || prot == null) returnnull;
        //IDictionaryEnumerator rotEnumerator = prot..GetEnumerator();
        prot.EnumRunning(out pmonkenum);
        IMoniker[] monikers = new IMoniker[1];
        while (pmonkenum.Next(1, monikers, pfetched) == 0)
          IBindCtx pctx; 
          string filepathname;
          CreateBindCtx(0, out pctx);
          // Get the name of the file
          monikers[0].GetDisplayName(pctx, null, out filepathname);
          // Clean up
          // Search for the workbook//Console.WriteLine(filepathname);if (filepathname.Replace("/","\\").IndexOf(xlfile) != -1)
            // Get a handle on the workbook
            prot.GetObject(monikers[0], out roval);
            return roval as Workbook;
        // Clean upif (prot != null) Marshal.ReleaseComObject(prot);
        if (pmonkenum != null) Marshal.ReleaseComObject(pmonkenum);


The code works fine and I am able to work with the Excel workbook UNTIL no other workbook is open in the system(another workbook opened by double clicking the file in the local system).

The following is the scenario:

1) I opened a workbook from explorer by double clicking it. Let's call it Excel A. This started an EXCEL.EXE process.

2) I navigated to another Excel workbook from my Windows Form web browser. Let's call it Excel B. Excel B opens in the Form.It uses the already existing EXCEL.EXE started in step 1.

3) Now if I try to edit Excel A(opened in step 1).It does not allow me. The focus is always there on Excel B(navigated in step 2). I cannot edit the cells, select text or even close Excel A.

As I see it, this is a focus issue. One of the statements from the Microsoft Kb article

http://support.microsoft.com/kb/304662/en-us is

"An ActiveX document that is hosted in the WebBrowser control is always active; therefore, unlike traditional OLE embedded objects, there is no sense of in-place activation."

1)Can you suggest me if I there is a way to navigate to an Excel by opening a new instance of EXCEL.EXE.

2) Or is there a way to shift focus between Excel A and Excel B so that both are editable.

3) Or is there an alternative to web browser contorl to embed Excel documents in C# forms.

I think an answer to 2) would be helpful because Excel 2007 tries to use a single instance of EXCEL.EXE for any number of workbooks.

For now, I've changed the file associations so that Excel 2007 opens a new instance each time it is double clicked.I've tried enabling and disabling " IgnoreOtherApplications that use DDE" option in Excel Options but the issue remains.

Environment: Visual studio 2005, Excel 2003 and 2007, .net framework 2.0.

The code is in C#.





<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure