craigdev
asked on
Writing object()() to excel fails
I am writing a table of data into excel using the code below:
app = CreateObject("Excel.Applic ation") 'New Excel.Application
app.DisplayAlerts = False
wkbk = app.Workbooks.Open(templat e)
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.InteropServ ices.COMEx ception (0x800A03EC): Exception from HRESULT: 0x800A03EC
at System.RuntimeType.Forward CallToInvo keMember(S tring memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Excel.Range.set_Value(Obje ct RangeValueDataType, Object )
app = CreateObject("Excel.Applic
app.DisplayAlerts = False
wkbk = app.Workbooks.Open(templat
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.InteropServ
at System.RuntimeType.Forward
at Excel.Range.set_Value(Obje
ASKER
Im catching it already, i just need to know how to stop excel from throwing the exception in the first place
even if you type an incorrect formula in excel yourself it wont let you.
can you describe what oData is?
can you describe what oData is?
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
The new location is http://msdn.microsoft.com/en-us/library/4f9sc85k.aspx.
try
oRange.Value = oData
catch ex as exception
' do nothing here
end try