Solved

Writing object()() to excel fails

Posted on 2006-11-24
6
290 Views
Last Modified: 2008-06-02
I am writing a table of data into excel using the code below:

            app = CreateObject("Excel.Application") 'New Excel.Application
            app.DisplayAlerts = False

            wkbk = app.Workbooks.Open(template)
            wksheet = wkbk.Worksheets(sheetName)

            Dim oRange As Excel.Range = wksheet.Range(startCell)
            oRange = oRange.Resize(RowCount, ColumnCount)

            oRange.Value = oData

            'save
            wkbk.SaveAs(saveFile, format)


The oData object()() has data and formulae and if the formulae are correct I do not get an exception. When a formula is invalid I get the exception below. Is there a way to ingore this so that excel will accept all of the formulae anyway, even if they are invalid?


 System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Excel.Range.set_Value(Object RangeValueDataType, Object )
0
Comment
Question by:craigdev
6 Comments
 
LVL 8

Expert Comment

by:doraiswamy
ID: 18007219
Maybe you can put it in a try catch block as below:

try
   oRange.Value = oData
catch ex as exception
' do nothing here
end try
0
 
LVL 1

Author Comment

by:craigdev
ID: 18007254
Im catching it already, i just need to know how to stop excel from throwing the exception in the first place
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 18007300
even if you type an incorrect formula in excel yourself it wont let you.
can you describe what oData is?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:craigdev
ID: 18007527
       Dim oData(rowsCount - 1, colsCount - 1) As Object

then i set each row/column value to be either a formula such as =A1*B1, or data value
sometimes i get errors in the formulae for whatever reason. I would rather write the formula out anyway and display as an invalid formula in excel. At the moment I cannot write any data out when there is a problem with a formula.

0
 
LVL 13

Accepted Solution

by:
newyuppie earned 500 total points
ID: 18007654
here's what a quick google search turned up for you exception code:

Regional Settings Cause Some Excel Methods to Return an Error

If the locale selected in an end user's regional settings does not match the installed language for Microsoft Office Excel 2003, he or she might receive the following errors when calling certain Excel methods and properties:

    A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll.

    Additional information: Exception from HRESULT: 0x800A03EC.

-or-

    A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in ExcelProject.dll.

    Additional information: Old format or invalid type library.

For details on correcting this problem, see Globalization and Localization of Office Solutions.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wroritroubleshootinginofficeatruntime.asp

0
 

Expert Comment

by:whitehen
ID: 21692297
The link to the resource suggested in the Accepted Solution has changed.
The new location is http://msdn.microsoft.com/en-us/library/4f9sc85k.aspx.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I change force the Y axis Maximum in a Visual Studio Chart 5 31
vb.net 2 37
Point to Current Row Ater Refresh Datagridview 3 21
Variable Event ? 3 23
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now