Hi.
I am trying to load VBA project from my DLL library on C#, and I am trying the next code:
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
doc.SendStringToExecute("(load \"C:\\\\project.dvb\") ", false, false, true);
How I can load my VBA project with C#?
Thanks beforehand,
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
You can surely use SendStringToExecute() to load VBA project and run macro in it, provided you have the command input entered correctly. In your case, you use command "VBALOAD", not "LOAD".
You can also use AutoCAD COM API to load/run VBA/VBA Macro. The sample code below uses "dynamic", so that no reference to AutoCAD COM libraries are necessary:
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using CadApp = Autodesk.AutoCAD.ApplicationServices.Application; [assembly: CommandClass(typeof(RunningVBA.Commands))] namespace RunningVBA { public class Commands { private const string VBA_PATH = @"C:\Users\norm\Documents\Visual Studio 2015\Projects\Acad NET\RunningVBA\MyVbaProject.dvb"; private const string VBA_MACRO = @"MyVbaModule.MyVbaMacro"; [CommandMethod("DocCmd")] public static void RunDocCommand() { Document dwg = CadApp.DocumentManager.MdiActiveDocument; Editor ed = dwg.Editor; dynamic comApp = CadApp.AcadApplication; comApp.LoadDVB(VBA_PATH); comApp.RunMacro(VBA_MACRO); } } }
Then, this is the VBA code in module called "MyVbaModule", saved in MyVbaProject.dvb:
Option Explicit Public Sub MyVbaMacro() ThisDrawing.Utility.Prompt vbCr & "MyVbaMacro: Hello World!" End Sub
As you can see, it is fairly simple. HTH.
Can't find what you're looking for? Ask the community or share your knowledge.