tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,913
- Office Version
- 365
- 2019
- Platform
- Windows
This site shows how to create a dll in Visual Studio:
Here is the C# code:
This is the VBA code:
In order for the VBA code to run, a reference to SimpleCalc must be added in the VB editor.
The C# code is saved on my PC and everything works as expected.
My question is if I send this to another person, what would they have to do to make the VBA work? I assume references "do not travel" with the workbook.
Would I need to send the C# code as well and if so, where should that be saved?
Thanks
Code:
https://www.youtube.com/watch?v=SoO_uUPfHOI&t=472s
Here is the C# code:
Code:
using System.Runtime.InteropServices;
namespace SimpleCalc
{
[ComVisible(true)]
public class Calculation {
private int numone = 0;
private int numtwo = 0;
public void SetNumOne(int number) {
numone = number;
}
public void SetNumTwo(int number)
{
numtwo = number;
}
public int addnumbers() {
return numone + numtwo;
}
}
}
This is the VBA code:
Code:
Option Explicit
Sub Test()
Dim obj As New SimpleCalc.Calculation
obj.setnumone (10)
obj.setnumtwo (20)
Debug.Print obj.addnumbers()
End Sub
In order for the VBA code to run, a reference to SimpleCalc must be added in the VB editor.
The C# code is saved on my PC and everything works as expected.
My question is if I send this to another person, what would they have to do to make the VBA work? I assume references "do not travel" with the workbook.
Would I need to send the C# code as well and if so, where should that be saved?
Thanks