To further define this problem so I will not get suggestions on using correct
code, I'm including the following example:
1. In Visual Basic, I add a reference to Excel 2007 by going to "Project,"
"Add Reference...," click on the COM Tab, and selecting "Microsoft Excel 12.0
Object Library."
2. I enter the following code into Visual Basic:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oXLApp As Microsoft.Office.Interop.Excel.Application
Dim oXLBook As Microsoft.Office.Interop.Excel.Workbook
oXLApp = New Microsoft.Office.Interop.Excel.Application
oXLApp.Visible = True
oXLBook = oXLApp.Workbooks.Add 'Exception error always occurs
at this point after new workbook is added
oXLApp = Nothing
End Sub
End Class
The following is the detailed error information returned by Visual Basic:
System.Runtime.InteropServices.COMException {"The server threw an exception.
(Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"}
Data {System.Collections.ListDictionaryInternal}
Count 0
IfFixedSize False
IsReadOnly False
IsSynchronized False
Item In order to evaluate an indexed property, the property must be
qualified and the arguments must be explicitly supplied by the user.
Keys {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
SyncRoot {Object}
Values {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
ErrorCode -2147417851
HelpLink Nothing
InnerException Nothing
Message "The server threw an exception. (Exception from HRESULT:
0x80010105 (RPC_E_SERVERFAULT))"
Source "Microsoft.Office.Interop.Excel"
StackTrace " at Microsoft.Office.Interop.Excel.Workbooks.Add(Object
Template) at WindowsApplication1.Form1.Button1_Click(Object sender,
EventArgs e) in C:\Users\Administrator\AppData\Local\Temporary
Projects\WindowsApplication1\Form1.vb:line 9 at
System.Windows.Forms.Control.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnClick(EventArgs e) at
System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at
System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32
clicks) at System.Windows.Forms.Control.WndProc(Message& m) at
System.Windows.Forms.ButtonBase.WndProc(Message& m) at
System.Windows.Forms.Button.WndProc(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at
System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam) at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context) at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context) at
System.Windows.Forms.Application.Run(ApplicationContext context) at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine) at WindowsApplication1.My.MyApplication.Main(String[] Args)
in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at
System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at
System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args) at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at
System.Threading.ThreadHelper.ThreadStart_Context(Object state) at
System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state) at
System.Threading.ThreadHelper.ThreadStart()"
TargetSite {System.Reflection.RuntimeMethodInfo}
Attributes 1478
CallingConvention 33
ContainsGernericParameters False
DeclaringType {Name = "Workbooks" FullName =
"Microsoft.Office.Interop.Excel.Workbooks"}
IsAbstract True
IsAssembly False
IsConstructor False
IsFamily False
IsFamilyAndAssembly False
IsFamilyOrAssemble False
IsFinal False
IsGernericMethod False
IsGernericMethodDefinition False
IsHideBySig False
IsPublic True
IsSpecialName False
IsStatic False
IsVirtual True
MemberType System.Reflection.MemberTypes.Method
MetadataToken 100665664
MethodHandle {System.RuntimeMethodHandle}
Module {System.Reflection.Module}
Name "Add"
ReflectedType {Name = "Workbooks" FullName =
"Microsoft.Office.Interop.Excel.Workbooks"}
ReturnParameter {System.Reflection.ParameterInfo}
ReturnType {Name = "Workbook" FullName =
"Microsoft.Office.Interop.Excel.Workbook"}
ReturnTypeCustomAttributes {System.Reflection.ParameterInfo}
Based on all the postings I've done and numerous people commenting on the
code and providing suggestions, I can only assume that it is some "setting"
within Excel and Word that is causing this problem.
Any suggestions?
Claude