Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

Writing object()() to excel fails

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
craigdev
Asked:
craigdev
1 Solution
 
doraiswamyCommented:
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
 
craigdevAuthor Commented:
Im catching it already, i just need to know how to stop excel from throwing the exception in the first place
0
 
newyuppieCommented:
even if you type an incorrect formula in excel yourself it wont let you.
can you describe what oData is?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
craigdevAuthor Commented:
       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
 
newyuppieCommented:
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
 
whitehenCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now