Vb.net VB中的趋势线常数
我是VB新手,但看起来这应该很简单。我试图在我的VB项目中获得线性趋势线的常数Vb.net VB中的趋势线常数,vb.net,excel,Vb.net,Excel,我是VB新手,但看起来这应该很简单。我试图在我的VB项目中获得线性趋势线的常数 Dim WStemp1 As WorksheetFunction Dim WStemp2 As WorksheetFunction X1_home = WStemp1.Index(WStemp2.LinEst(y_values, x_values), 1, 1) C1_home = WStemp1.Index(WStemp2.LinEst(y_values, x_values), 1
Dim WStemp1 As WorksheetFunction
Dim WStemp2 As WorksheetFunction
X1_home = WStemp1.Index(WStemp2.LinEst(y_values, x_values), 1, 1)
C1_home = WStemp1.Index(WStemp2.LinEst(y_values, x_values), 1, 2)
这段代码在vba中运行良好,但出现以下错误
An unhandled exception of type 'System.NullReferenceException' occurred in myApp.exe
Additional information: Object reference not set to an instance of an object.
If there is a handler for this exception, the program may be safely continued.
非常感谢您的帮助您必须从Excel应用程序中恢复工作表功能对象。例如:
Dim App As New Excel.Application
Dim ExcelFunc As Excel.WorksheetFunction = App.WorksheetFunction
'Use the excel function
Dim avg As Double
avg = ExcelFunc.Average(1, 2, 3, 4, 5)
'release objects and terminate Excel application
ExcelFunc = Nothing
App.Quit()
App = Nothing
干杯展示如何实例化
WStemp1
和WStemp2
就是这样,我不启动它们。您建议如何执行此操作?WorksheetFunction
是Excel应用程序对象的属性-您的项目中是否有对Excel的引用?通常您会使用类似于xlApp.WorksheetFunction
的东西,其中xlApp
是您的Excel应用程序实例。