我想编写一个宏来导出VBA编辑器项目视图中存在的宏,因为无法导出多个文件!
我之所以这样做是因为我需要.bas
和.cls
文件来创建doxygen文档。
如果有人知道更简单的解决方案,请告诉我。否则:如何从项目中一次导出所有VBA代码文件?
致以最诚挚的问候,谢谢!
答案 0 :(得分:0)
答案 1 :(得分:0)
工作示例,导出.bas
,。cls
和.frm
模块:
Option Explicit
Public Sub MakeDoxy()
Dim rootDir As String
Dim sourceDir As String
rootDir = GetFolder("C:\") & "\"
sourceDir = rootDir & "source\"
If Dir(rootDir, vbDirectory) = "" Then
MkDir rootDir
End If
If Dir(sourceDir, vbDirectory) = "" Then
MkDir sourceDir
End If
ExportVBAModules (sourceDir)
End Sub
Private Sub ExportVBAModules(ByVal sourceDir As String)
Dim objVBComp As VBComponent
Dim objVBProj As VBProject
Dim ext As String
Set objVBProj = ThisWorkbook.VBProject
For Each objVBComp In objVBProj.VBComponents
' We don't export THIS module
If objVBComp.Name = "MakeDoxygen" Then GoTo Skip
If Dir(sourceDir & objVBComp.Name, vbDirectory) = "" Then
MkDir sourceDir & objVBComp.Name
End If
Select Case objVBComp.Type
Case vbext_ct_ClassModule: ext = ".cls"
Case vbext_ct_Document: GoTo Skip
Case vbext_ct_StdModule: ext = ".bas"
Case vbext_ct_MSForm: ext = ".frm"
Case Else: GoTo Skip
End Select
objVBComp.Export sourceDir & objVBComp.Name & "\" & objVBComp.Name & ext
Skip:
Next
End Sub
Private Function GetFolder(strPath As String) As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select ''VBADoxy'' Root Folder"
.AllowMultiSelect = False
.InitialFileName = strPath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function