-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathCSharp_with_VBA.cs
More file actions
69 lines (58 loc) · 1.71 KB
/
CSharp_with_VBA.cs
File metadata and controls
69 lines (58 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
C# with VBA C Sharp with vba dll with csharp
File>New Project> Class Library
In the class:
===================
namespace VitoshNamespace
{
public class Vitosh5
{
public int intNumberOne = 10001;
public int intNumberTwo = 20001;
public string Information()
{
string strResult = intNumberOne + " " + intNumberTwo;
return strResult;
}
public string AdvancedInformation()
{
string strResult = "intNumberOne is " + intNumberOne + ". intNumberTwo is " + intNumberTwo;
return strResult;
}
public string AdvancedInformation2()
{
string strResult = "Built by Vityata";
return strResult;
}
public string AdvancedInformation3()
{
string strResult = this.AdvancedInformation2() + " YUP!";
return strResult;
}
}
}
===================
Menu>Project ~~ Properties
Application> Assembly Information> Checkbox - Make assembly COM-Visible
The description will be the one showing in VBA libraries
Build
Output path
Checkpox on "Register for COM interop"
===================
F6 (Build Solution)
===================
Then in VBE > Extras>Library>Browse>Take the *.tlb
Insert like this:
Option Explicit
Sub TestMe()
Dim objNumbers As New Vitosh5
Debug.Print objNumbers.intnumberone
Debug.Print objNumbers.intnumbertwo
Debug.Print objNumbers.Information
Debug.Print objNumbers.advancedinformation
Debug.Print objNumbers.advancedinformation2
Debug.Print objNumbers.AdvancedInformation3
End Sub
If something is changed in the Class code:
-> new release is needed;
-> reload the Excel File;
-> reassign