Home All Groups Group Topic Archive Search About

Using excel XIRR FUNCTION IN A VB 2005 program

Author
14 Nov 2006 8:01 PM
Carlos
I'm getting RPC error when I try to register analys32.xll in the VB program.
ErrorCode=-2147417851
  Message="El servidor lanzó una excepción. (Exception from HRESULT:
0x80010105 (RPC_E_SERVERFAULT))"
  Source="Microsoft.Office.Interop.Excel"
  StackTrace:
       at Microsoft.Office.Interop.Excel.ApplicationClass.RegisterXLL(String
Filename)
       at WindowsApplication9.Form1.Button1_Click(Object sender, EventArgs
e) in C:\Documents and Settings\ccuervo\Mis documentos\Visual Studio
2005\Projects\WindowsApplication9\WindowsApplication9\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 WindowsApplication9.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()
The code:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        Dim objExcel As Microsoft.Office.Interop.Excel.Application
        objExcel = New Microsoft.Office.Interop.Excel.Application
        objExcel.Workbooks.Open(objExcel.Application.LibraryPath & _
         "\Análisis\atpvbaen.XLa")
        objExcel.RegisterXLL(objExcel.Application.LibraryPath & _
                "\Análisis\analys32.xll")
        Dim p(4) As Double
        p(0) = -4504000.0
        p(1) = 66183.78
        p(2) = 86326.67
        p(3) = 86326.67
        p(4) = 4524142.89

        Dim X As Double
        '  objExcel.AddIns.Add("c:\Analisis\atpvbaen.XLa")
        Dim d(4) As Date
        d(0) = #1/1/1998#
        d(1) = #3/1/1998#
        d(2) = #10/30/1998#
        d(3) = #2/15/1999#
        d(4) = #4/1/1999#

        Debug.Print(objExcel.Run("xIrr", p, d)) ' Result: 0.374858599901199
        'objExcel.A()
        'MsgBox(X)
        objExcel.Quit()
        objExcel = Nothing


    End Sub
Anyone of you know how to solve this problem

Author
15 Nov 2006 3:33 PM
Robinson
> Anyone of you know how to solve this problem

Something I found:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=201281&SiteID=1

You might have to install .NET programmability support.