HighTechTalks DotNet Forums  

Excel Analysis Add-In Problem

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Excel Analysis Add-In Problem in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
MasterBlaster
 
Posts: n/a

Default Excel Analysis Add-In Problem - 05-21-2007 , 12:33 PM






I'm trying to utilize an analysis function called XIRR and I found a snippet
of code. Once it gets to this line:
'Run the AutoOpen macro in the add-in

objExcel.Workbooks("atpvbaen.xla").RunAutoMacros(M icrosoft.Office.Interop.Excel.XlRunAutoMacro.xlAut oOpen)

it blows up and jumps out of the function and doesn't generate an error or
anything. Any help would be appreciated. See full function code below:

Public Function xl_xIRR(ByRef dt As DataTable) As Double
Try
'Call Excel's XIRR() function. This is found in the Analysis
Toolpak add-in.
Dim objExcel As Microsoft.Office.Interop.Excel.Application
Dim MyDataRow As DataRow
Dim cnt As Int16 = 0
Dim Val As Double = 0
Dim Dates() As Date = New Date(dt.Rows.Count) {}
Dim CF() As Double = New Double(dt.Rows.Count) {}

For Each MyDataRow In dt.Rows
cnt += 1

Dates(cnt - 1) = MyDataRow("TradeDate")
CF(cnt - 1) = MyDataRow("Amount")
Next

objExcel = CreateObject("Excel.application")

'Open the Analysis Pack add-in
objExcel.Workbooks.Open(objExcel.Application.Libra ryPath &
"\Analysis\atpvbaen.xla")


'Run the AutoOpen macro in the add-in

objExcel.Workbooks("atpvbaen.xla").RunAutoMacros(M icrosoft.Office.Interop.Excel.XlRunAutoMacro.xlAut oOpen)


'Call the XIRR function
Val = objExcel.Application.Run("atpvbaen.xla!XIRR", CF, Dates)

'Cleanup
objExcel.Quit()
objExcel = Nothing

Return Val

Catch ex As Exception
Throw ex
End Try
End Function


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.