So I have this DLL code here...
Public Class Algebra
Public Function Addition(ByVal x As Long, ByVal y As Long)
Dim mysum As Long
mysum = x + y
Return mysum
End Function
End Class
And my Excel VBA is ...
Public Sub CommandButton1_Click()
Dim myAlgebra As Algebra
Set myAlgebra = New Algebra
Dim mysum As Long
mysum = myAlgebra.Addition(4, 4)
MsgBox ("HELLO WORLD " & mysum)
End Sub
Now all this works fine.
My next task is to edit a value of a Cell, like say Cells(8,1).Value = "HELLO", using the DLL.
I tried inserting-
ThisWorkbook.Sheets(1).Cells(10, 1).Value = "HELLO"
inside the Function but it just throws a syntax error. I guess I need to create an object that would contain Excel Workbook? Tho Im not sure how to do that....
EDIT: As advised by GSerg, here's my modifications..
For DLL Side...
Public Function EditCell(ByRef myWB As Object)
myWB = "HELLO"
End Function
For VBA...
Set myrange = ThisWorkbook.Sheets(1).Range("A10")
myAlgebra.EditCell (myrange)
So this runs without errors but A10 cell was not populated...
EDIT#2: Question answered. I've posted an answer below. Thanks to all that helped!