Nishant
Nishant

Reputation: 905

Open Excel Workbook with vba code - error to notify VSTO

I am trying to open an Excel file from my C# code.

workBook = workBooks.Open(fileName,               //filename
                          0,                      //updatelinks
                          true,                   //readonly
                          5,                      //format
                          "",                     //password
                          "",                     //WriteResPassword
                          true,                   //IgnoreReadOnlyRecommended
                          XlPlatform.xlWindows,   //Origin
                          "\t",                   //Delimiter
                          false,                  //Editable
                          false,                  //Notify
                          0,                      //Converter
                          true,                   //AddToMru
                          1,                      //Local
                          0);                     //CorruptLoad

I see that the code hangs at workBooks.Open if the excel has some error within it. I have kept the display property to true and that is when I noticed that there is an error in the excel. On further investigation I got to know that the error is caused due to some vba code in the excel which is failing. My requirement is how do I get my C# code to be notified about this, so that it can ignore the error within the file or ignore the file itself?

Upvotes: 0

Views: 1591

Answers (2)

em3ricasforsale
em3ricasforsale

Reputation: 352

Another alternative to using the intreop library is http://code.google.com/p/excellibrary/ which doesn't require you to have excel or the excel.dll installed and registered to your machine or server that you are putting it on.

Upvotes: 1

Remy
Remy

Reputation: 12713

What do you try to achive? Maybe just using the Microsoft Open XML SDK would be enough?
You can read, create and edit Excel files with it.

Upvotes: 1

Related Questions