How can a form with command buttons created with VSTA run macros made with VBA?

Hello,
How can a form with command buttons created with VSTA run macros made with VBA?
Greetings!
  •  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
           [CgsAddInMacro]
            public void GetMacros()
            {
                if (!corelApp.InitializeVBA())
                    return;
                GMSProjects projects = corelApp.GMSManager.Projects;
                for (int i = 1; i <= projects.Count; i++)
                {
                    GMSMacros macros = projects[i].Macros;
                    for (int r = 1; r <= macros.Count; r++)
                    {
                        string name = macros[r].Name;
                        MessageBox.Show(name);
                    }
                }
            }
    
    
            [CgsAddInMacro]
            public void LoadMacro()
            {
                if (!corelApp.InitializeVBA())
                    return;
                string path = @"D:\Downloads\Shaping-X64-2023.gms";
                GMSProject gmp = corelApp.GMSManager.Projects.Load(path);
    
                GMSMacros macros = gmp.Macros;
         
                for (int r = 1; r <= macros.Count; r++)
                {
                    string name = macros[r].Name;
              
                    if (name.Equals("Shapes.Go"))
                    {
                       
                        macros[r].Run();
                        
                    }
                }
                gmp.Unload();
            }
            [CgsAddInMacro]
            public void LoadMacro2()
            {
                if (!corelApp.InitializeVBA())
                    return;
                string path = @"D:\Downloads\Shaping-X64-2023.gms";
                corelApp.GMSManager.RunMacro("Shaping2023", "Shapes.Go");
                
            }
    
    • Hello,
      C# is not my best program language. Please explain, at least a little, how to use this code? Need I Visual Studio? I use Visual Studio 19
      Greetings!

      • for native coreldraw vsta support, you will need visual studio, I don't know the specific version as I don't use coreldraw's native vsta, but it doesn't make much sense to use vsta if you are not going to use c#, vba is better for small projects. i use c# because i have no interest in learning vba

        • Thank You for this answer!
          Problem is a little different. I will try to explain. But i think that only people using VSTA, VBA, CorelDraw may understand. Because theoretically all must work, but not work.  

          • maybe it's a misunderstanding, I assumed you already had a VSTA form, which in CorelDraw's case is a WinForm form in C#.

            • 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