Microsoft KB Archive/262961

= WD2000: Sample Macro to Return Macro and Procedure Names =

Article ID: 262961

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Word 2000 Standard Edition

-



This article was previously published under Q262961



SUMMARY
This article provides a sample macro that you can use to list the names of macros that are contained in active projects in Word 2000.

The ListAllMacroNames sample macro lists the names of macros in all projects that are not locked for viewing. For projects that are locked, the sample macro displays a &quot;Macros in this locked project will not be listed&quot; message, and it does not list the macros names. If you want to view a list of macros, point to Macro on the Tools menu, and then click Macros.

NOTE: When you load an add-in program, projects that are contained in it are locked. Therefore, the ListAllMacroNames sample macro does not list macros in add-in programs if the projects are locked.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

212536 OFF2000: How to Run Sample Code from Knowledge Base Articles

NOTE: For the following macro to run, you must add the Visual Basic for Applications (VBA) Extensibility reference. To do this, follow these steps:
 * 1) On the Tools menu, point to Macro, and then click Visual Basic Editor.
 * 2) In the Visual Basic Editor, click References on the Tools menu.
 * 3) In the Available References list, click to select the Microsoft Visual Basic for Applications Extensibility check box.
 * 4) Click OK to close the References dialog box.

To list the macro names stored in the public projects, create the following VBA macro: Sub ListAllMacroNames

Dim pj As VBProject Dim vbcomp As VBComponent Dim curMacro As String, newMacro As String Dim x As String Dim y As String

On Error Resume Next curMacro = &quot;&quot; Documents.Add

For Each pj In Application.VBE.VBProjects x = pj.FileName y = pj.Protection If x <> &quot;&quot; Then If y <> &quot;1&quot; Then Selection.InsertAfter &quot;The &quot; & Chr(34) & x & Chr(34) & _ &quot; project contains &quot; & &quot;the following macro names:&quot; & vbCr Selection.InsertAfter vbCr For Each vbcomp In pj.VBComponents For i = 1 To vbcomp.CodeModule.CountOfLines newMacro = vbcomp.CodeModule.ProcOfLine(Line:=i, _                 prockind:=vbext_pk_Proc) If curMacro <> newMacro Then curMacro = newMacro If curMacro <> &quot;&quot; And curMacro <> &quot;app_NewDocument&quot; Then Selection.InsertAfter newMacro & vbCr Selection.Collapse wdCollapseEnd End If              End If            Next Next Else Selection.InsertAfter &quot;The project &quot; & Chr(34) & x & Chr(34) & _ &quot; is locked. &quot; & &quot;Macros in this locked project will not be&quot; _ & &quot; listed.&quot; & vbCr & vbCr End If    Selection.InsertAfter vbCr End If  x = &quot;&quot; Next Selection.Collapse wdCollapseEnd End Sub

Additional query words: vb vba vbe

Keywords: kbhowto kbmacroexample KB262961

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.