Hello,How can a form with command buttons created with VSTA run macros made with VBA?Greetings!
Hello, again!
Yes, I have userform VSTA created. More then. I have many command buttons on this form that open other VSTA created userforms.
All code is put in add-in dll. The add-in opens/starts when Corel Draw is started.
Problem is that for me is impossible to make subs in dll file to work.
This is the reason to ask metod to run VBA code from VSTA created form.
Idel metod is to run VSTA created SUB from VSTA created form, but for now it's impossible.
All time appears error message, that Entry point in dll not found?!
Only Application.Start, Document.Open events are accessible....
I will see exact again what events work.
Greetings!
started to understand now, you are using a version prior to x7, but the code may work, you can check the object model in the object inspection window of visual studio. But you will only be able to run vba in c# with the vsta template, to run from c# in vba you need to export your functions to iunknow and idispatch, and export your dll as com, you can start here, learn.microsoft.com/.../example-com-class
hi, now that i'm on the computer i wrote this demo example, for you to use c# functions in vba
Dll project C#
using System; using System.Runtime.InteropServices; namespace bonus630.SimpleCom { [ComVisible(true)] [Guid("6b53689e-c03a-463f-bb2e-088f1b71f5c3")] [ClassInterface(ClassInterfaceType.None)] public class Operations : IOperations { public int Sum(int a, int b) { return a + b; } } [ComVisible(true)] [Guid("f3df60d2-6454-452e-967b-417bda067347")] [InterfaceType(ComInterfaceType.InterfaceIsDual)] public interface IOperations { int Sum(int a, int b); } }
VBA
Sub SumFromCom() Dim obj As SimpleCom.Operations Dim result As Integer Set obj = New SimpleCom.Operations result = obj.Sum(1, 2) Debug.Print resultEnd Sub
In C# project dll
set the correct platform in my case is x86
Use a namespace and strong name and sign your dll
Use regasm in .net framework folder to registre your dll
Add reference in VBA
result
Hello, againThank You very mach for this answer with detailed explanation.I will try and write You result.Thank You!!!