2014-07-23 77 views
-1

我想寫出口宏存在於VBA編輯器項目視圖,因爲是無法導出多個文件宏!VBA宏宏出口

我之所以要這樣做,是因爲我需要.bas.cls文件來創建一個doxygen文檔。

如果有人知道一個簡單的解決方案,請讓我知道。否則:如何從項目中一次性導出所有VBA代碼文件?

最好的問候,並感謝您!

+0

'如果(typeof運算(T)== typeof運算(UINT16))' –

回答

0

首先,不用說,無論哪個代碼「接觸你的代碼」必須是可信

是的,這是可能的,你可以使用VBProject和的VBComponent去實現它。請看看herehere。這些鏈接很好地解釋瞭如何去做你所問的。

+0

加我寫了這樣做的代碼。 – displayname

+0

@StefanFalk如果你認爲它會做得很好,請添加你的答案(不要編輯我的)。 – Noldor130884

+0

我的編輯只是代碼,做了你對誰來這裏後跟我們的人建議 – displayname

0

工作示例,出口.bascls.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