The following code written for Excel 2007 formats a range as a table without issue.
SourceRange.Worksheet.ListObjects.Add(XlListObjectSourceType.xlSrcRange,
SourceRange, System.Type.Missing, XlYesNoGuess.xlYes, System.Type.Missing).Name = TableName;
SourceRange.Worksheet.ListObjects[TableName].TableStyle = TableStyleName;
SourceRange.AutoFilter(1, Type.Missing, XlAutoFilterOperator.xlAnd, Type.Missing, true);
if (IsGroupTable)
{
SourceRange.Rows.Group(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
When I try to use the same code in Excel 2003, I get the following error:
Type : System.Runtime.InteropServices.COMException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
Source : mscorlib
Help link :
ErrorCode : -2147352573
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Object ForwardCallToInvokeMember(System.String, System.Reflection.BindingFlags, System.Object, Int32[], System.Runtime.Remoting.Proxies.MessageData ByRef)
Stack Trace : at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.ListObjects.Add(XlListObjectSourceType SourceType, Object Source, Object LinkSource, XlYesNoGuess XlListObjectHasHeaders, Object Destination)
I'm not sure what is causing this error to occur, is it salvageable?
ListObject has been heavily changed moving up to 2007. I suggest you look at the changes to ListObject here to figure out what it is your trying to use that 2003 doesn't support.
User contributions licensed under CC BY-SA 3.0