
Excel 2007을 사용하고 있습니다. 이 질문에 대한 내 통합 문서 이름은 PrintCode.xlsm입니다.
열려 있는 통합 문서 내에서 모든 매크로 이름과 코드를 인쇄하는 매크로 또는 VBA 코드가 있습니까?
웹에서 몇 가지 예를 찾았지만 아무 것도 작동하지 않는 것 같나요?
답변1
나는 이것을 찾았습니다. 이것이 당신에게 필요한 것입니다:Visual Basic 6.0을 사용하여 Excel 통합 문서에서 매크로 이름을 검색하는 방법:
버튼에 대한 클릭 이벤트 핸들러 프로시저를 정의합니다. 이 절차에 대해 다음 코드를 사용하여 C:\Abc.xls에 정의된 매크로에 대한 정보를 표시합니다.
Private Sub Command1_Click()
' Declare variables to access the Excel workbook.
Dim objXLApp As Excel.Application
Dim objXLWorkbooks As Excel.Workbooks
Dim objXLABC As Excel.Workbook
' Declare variables to access the macros in the workbook.
Dim objProject As VBIDE.VBProject
Dim objComponent As VBIDE.VBComponent
Dim objCode As VBIDE.CodeModule
' Declare other miscellaneous variables.
Dim iLine As Integer
Dim sProcName As String
Dim pk As vbext_ProcKind
' Open Excel, and open the workbook.
Set objXLApp = New Excel.Application
Set objXLWorkbooks = objXLApp.Workbooks
Set objXLABC = objXLWorkbooks.Open("C:\ABC.XLS")
' Empty the list box.
List1.Clear
' Get the project details in the workbook.
Set objProject = objXLABC.VBProject
' Iterate through each component in the project.
For Each objComponent In objProject.VBComponents
' Find the code module for the project.
Set objCode = objComponent.CodeModule
' Scan through the code module, looking for procedures.
iLine = 1
Do While iLine < objCode.CountOfLines
sProcName = objCode.ProcOfLine(iLine, pk)
If sProcName <> "" Then
' Found a procedure. Display its details, and then skip
' to the end of the procedure.
List1.AddItem objComponent.Name & vbTab & sProcName
iLine = iLine + objCode.ProcCountLines(sProcName, pk)
Else
' This line has no procedure, so go to the next line.
iLine = iLine + 1
End If
Loop
Set objCode = Nothing
Set objComponent = Nothing
Next
Set objProject = Nothing
' Clean up and exit.
objXLABC.Close
objXLApp.Quit
End Sub