views:

624

answers:

5

I need to use the Microsoft.Office.Interop.Word namespace to extract if a Word document contains macros, and which ones. The MSDN documentation for this namespace doesn't give much information compared to the documentation on other .Net classes. Where can I get more informations about this namespaces (examples, complete documentation, etc.). I already searched on Google and SO but didn't much information.

+2  A: 

Here's where you can learn more about this for Office 2007/Office 2010: http://msdn.microsoft.com/en-us/library/dd925808.aspx

Otaku
A: 

Microsoft.Vbe.Interop is the namespace for VBA. (VBE is Visual Basic for Application Extensibility 5.3.) Keywords to help you search are VBProject, VBComponent, and CodeModule.

MSDN Search for VBProject will get you started. http://social.msdn.microsoft.com/Search/en-US?query=VBProject&ac=8.

The following article is for VBA, but it is easily converted. WD2000: Sample Macro to Return Macro and Procedure Names at http://support.microsoft.com/kb/262961.

AMissico
Expect an exception "Programmatic access to Visual Basic Project is not trusted." when you try this. Google the error message for more information. (You'll also find some people trying to do the same thing as you!)
MZB
You can change this through macro security on the "Trusted Publishers" tab. Moreover, adding a certificate to the project with the proper macro security setting will bypass this message.
AMissico
A: 

The bulk of the documentation is in the VBA help file which ships with Microsoft Word - for Microsoft Word 2003 look for a file VBAWD10.CHM. Also check the Microsoft Office Visual Basic Reference (VBAOF11.CHM)

10 and 11 in the above are Word and Office version numbers - so your mileage will vary according to which version of Word you have installed. Also the naming isn't consistent in all versions of Word, so a search for everything VBA*.CHM will probably turn up most of the documentation you need.

These will answer most of your questions about the Word API.

Can't see an obvious way of finding the list of macros in an open document or template, however... Please add a comment to this answer if you do find a method, as I'd be interested to know.

(Note that every call can throw an exception when using Word interop. If Word has any modal dialog box open you'll get an exception, for example. Program accordingly).

MZB
@unknown - If you're going to down-vote something, a clue as to why the answer was unhelpful would be useful. (Having done something very similar to @rold2007 and looked for the same documentation, I'd be interested to know if there is a better source of information).
MZB
As @AMissico suggests, the Application.VBE property may be the place to look.
MZB
Only a guess, as there is only one answer to this question. I imagine the down vote is due to your referencing the Office and Word object model references and not the VBA/VBE references. Moreover, maybe because you are referencing VBA instead of a .NET Namespace.
AMissico
+1  A: 

There is no good documentation. The only resources are the MSDN (quiet bad) and some blogs. Maybe you can find some information here: http://blogs.msdn.com/mshneer/

crauscher
+2  A: 

http://msdn.microsoft.com/en-us/library/dd925808.aspx

reggie
@reggie: you posted the same link I posted 20 days ago
Otaku
-1, who upvoted this answer?
AMissico