Problems with Automaint Excel

C

Claude Hunter

I use Delphi to automate Excel and Word in a program that is used at work.
My organization has just recently upgraded all systems to Vista Enterprise
with Office 2007. The Delphi program no longer works properly. I get
"exception errors" whenever I try to load or add a workbook in Excel and
whenever I attempt to save a Word file. This only occurs on the new systems.

I've posted my code on several sites and all reponses indicate that I have
correct code.

My question is, "Are there any settings withon Excel, Word, or Vista that
could be affecting these functions in the automation of Excel and Word?" Our
IT staff does not know an any settings that would affect this.

Any suggestions?
 
N

NOPIK

My question is, "Are there any settings withon Excel, Word, or Vista that
could be affecting these functions in the automation of Excel and Word?"  Our
IT staff does not know an any settings that would affect this.

Any suggestions?
Probably, you used Delphi "Office" controls. They statically linked to
specific Office versions (Althrough, you can dynamically load proper
frontend). More detailed information can be found in Delphi help.
If speed not a limit - you can communicate over OLE and use lower
target Excel functionality only (you can use Office components to
define Office constants or, define them yourself):
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Workbooks.Open('Myfile.xls');

Will work for any Office version - but very slow.
 
N

NOPIK

For Vista, some of the possible problems decribed in (Originally for
Windows2000, but similar to Vista case):
http://support.microsoft.com/kb/264743

Access Rights collision can be easily tracked by running under
Administrator account (for Vista, it is more privileged account, than
generic Administrators group member) - in Virtual Machine, if
prohibited on actual system.
 
C

Claude Hunter

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
 
N

NOPIK

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.


Looks like there is no Template for your current context...
Did you tried to provide any?
Have you tried to open existing file?
 
N

NOPIK

Oops!

oXLBook = oXLApp.Workbooks.Add ???
For VB, objects assigned with SET (equlality will copy properties
between objects):
set oXLBook = oXLApp.Workbooks.Add
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top