Search code examples
c#ms-accessmacrosoffice-interop

Create a macro for Microsoft Access via Interop


Is it possible to create a new macro using C# using the Interop library in Microsoft Access in a similar fashion as Word, Excel, or PowerPoint? In the other applications, you have access to Microsoft.Vbe.Interop._VBComponent, which allows you to inject new macros, through the Document, Worksheet, or Presentation classes. It doesn't look like Access has anything similar to this. Access has an AllMacros list, but it appears to be read-only. I know how to execute the macro once it's in the project, but I need to be able to add macros dynamically. I would greatly appreciate anyone that could point me in the correct direction.


Solution

  • Taken from answers.microsoft.com:

    A macro in Access is a special database object, unlike in other Office applications where a macro is simply a VBA procedure without arguments. As far as I know you can't create an Access macro programmatically. -HansV MVP (April 27, 2011)

    There is another answer posted at the same question that says you can create new code/VBA objects using the VB Extensibility Library.