|
-
Sep 5th, 2012, 02:47 PM
#1
Thread Starter
New Member
Excel Functions in VB.net help
So, I'm trying to use the Linest function from Excel and I'm trying to implement it into my code. After trying many different ways, this is what I've currently done.
First, I added the Excel Interop to my project resources.
Then I tried this code:
Code:
Imports Microsoft.Office.Interop.Excel
Dim xl As Microsoft.Office.Interop.Excel.Application
Results = xl.WorksheetFunction.LinEst({1,2,3,4}, {5,6,7,8})
I get the following error:
Object reference not set to an instance of an object.
I changed it so I was setting xl as a NEW application instance with the code below:
Code:
Imports Microsoft.Office.Interop.Excel
Dim xl As New Microsoft.Office.Interop.Excel.Application
Results = xl.WorksheetFunction.LinEst({1,2,3,4}, {5,6,7,8})
I then got the following error:
Unable to cast object of type 'System.Object[*]' to type 'System.Object[]'.
I've tried many variations but, sadly, this is as close as I seem to be able to get (I imagine it's probably a pretty simple mistake of creating the correct instances and calling them correctly but, for the life of me, I can't seem to find out where to go from here so I figured I'd check with the experts. But I don't have the money for that so I came to you guys instead. 
Any help you can give me would be GREATLY appreciated. Thanks!
-
Sep 5th, 2012, 04:08 PM
#2
Thread Starter
New Member
Re: Excel Functions in VB.net help
Oops, left out a line.
Code:
Imports Microsoft.Office.Interop.Excel
Dim xl As New Microsoft.Office.Interop.Excel.Application
Dim Results() As Object
Results = xl.WorksheetFunction.LinEst({1,2,3,4}, {5,6,7,8})
Is it possible the issue has to do with the linest function returning something that can't be stored as an object?
-
Sep 5th, 2012, 04:29 PM
#3
Thread Starter
New Member
Re: Excel Functions in VB.net help
Nevermind. Fixed the issue.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|