I have this vba code
Dim strpath As String
Dim this As String
strpath = "C:\Users\johbra\Documents\Visual Studio 2010\Projects\WindowsApplication6\WindowsApplication6\bin\Debug\WindowsApplication6.exe"
this = Shell(strpath)
MsgBox this
I also have this function in a .net program
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
dothis()
Application.Exit()
End Sub
Function dothis()
Return "HI"
End Function
End Class
Im trying to get the vba code to give me a messagebox that says "HI".. Is this possible?
The most accepted and reliable way to call .NET code from VBA is to expose the .NET class as a COM class (no extra code needed, just tick the appropriate box in project properties), then add a reference the COM class in your VBA project, the way you would for any other other COM class, and call the function.
Here's a guide on how exactly this is done.
Please let me know if you need more details on how to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With