Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the macros defined in an Excel workbook

Tags:

excel

vba

vsto

Is there any way, in either VBA or C# code, to get a list of the existing macros defined in a workbook?

Ideally, this list would have a method definition signatures, but just getting a list of the available macros would be great.

Is this possible?

like image 612
Scott Weinstein Avatar asked Dec 21 '25 12:12

Scott Weinstein


1 Answers

I haven't done vba for Excel in a long time, but if I remember well, the object model for the code was inaccessible through scripting.

When you try to access it, you receive the following error.

Run-time error '1004':
Programmatic access to Visual Basic Project is not trusted

Try:

Tools | Macro | Security |Trusted Publisher Tab
[x] Trust access to Visual Basic Project

Now that you have access to the VB IDE, you could probably export the modules and make a text search in them, using vba / c#, using regular expressions to find sub and function declarations, then delete the exported modules.

I'm not sure if there is an other way to do this, but this should work.

You can take a look the following link, to get started with exporting the modules. http://www.developersdex.com/vb/message.asp?p=2677&ID=%3C4FCD0AE9-5DCB-4A96-8B3C-F19C63CD3635%40microsoft.com%3E

This is where I got the information about giving thrusted access to the VB IDE.

like image 198
Martin Avatar answered Dec 23 '25 12:12

Martin