本文介绍了返回所有宏的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在vba中,如何调用Word文档并获取其中包含的所有宏的列表?
In vba, how can i call a word document and get a list of all the macros it contains?
推荐答案
本文应该向您展示如何做到这一点(适用于Word 2000,但我认为它很可能适用于您使用的任何版本): WD2000:示例宏以返回宏和过程名称
This article should show you how to do it (it's for Word 2000 but I assume there's a good chance it'll work for whatever version you use): WD2000: Sample Macro to Return Macro and Procedure Names
这是该文章中的代码:
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 = ""
Documents.Add
For Each pj In Application.VBE.VBProjects
x = pj.FileName
y = pj.Protection
If x <> "" Then
If y <> "1" Then
Selection.InsertAfter "The " & Chr(34) & x & Chr(34) & _
" project contains " & "the following macro names:" & 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 <> "" And curMacro <> "app_NewDocument" Then
Selection.InsertAfter newMacro & vbCr
Selection.Collapse wdCollapseEnd
End If
End If
Next
Next
Else
Selection.InsertAfter "The project " & Chr(34) & x & Chr(34) & _
" is locked. " & "Macros in this locked project will not be" _
& " listed." & vbCr & vbCr
End If
Selection.InsertAfter vbCr
End If
x = ""
Next
Selection.Collapse wdCollapseEnd
End Sub
这篇关于返回所有宏的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!