I have build a function with different arguments in Python which I can recall in xls using xlwings.
When I try to use the same function in VBA though I get the following error:
AttributeError:'int' object has no attribute 'worksheet'
self.xl.Worksheet
This is the code in vba
Sub RefreshPrices()
Dim result As Variant
Dim wb As Workbook: Set wb = ActiveWorkbook
Dim ws As Worksheet
Set ws = wb.Sheets("Power Curve")
For i = 0 To 7
result = getPRICES_FWD(Cells(2, 1), Cells(6, 3 + i), Cells(7, 1), Cells(8, 2), Cells(9, 2))
wb.ws.Range(Cells(7, 3 + i * 4).Address, Cells(16, 4 + i * 4)).Value = result
Next
End Sub
'Autogenerated code by xlwings - changes will be lost with next import!
#Const App = "Microsoft Excel" 'Adjust when using outside of Excel
Function getPRICES_FWD(as_of_date, curveName, granularity, start_date, end_date)
If (Not Application.CommandBars("Standard").Controls(1).Enabled) Then Exit Function
#If App = "Microsoft Excel" Then
If TypeOf Application.Caller Is Range Then On Error GoTo failed
getPRICES_FWD = Py.CallUDF("Prices", "getPRICES_FWD", Array(as_of_date, curveName, granularity, start_date, end_date), ThisWorkbook, Application.Caller)
Exit Function
#Else
getPRICES_FWD = Py.CallUDF("Prices", "getPRICES_FWD", Array(as_of_date, curveName, granularity, start_date, end_date))
Exit Function
#End If
failed:
getPRICES_FWD = Err.Description
End Function
Any help would be much appreciated
Thanks
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…