Exporting MS Access Forms and Class / Modules Recursively to text files?

后端 未结 6 1230
时光取名叫无心
时光取名叫无心 2020-12-01 05:57

I found some code on an ancient message board that nicely exports all of the VBA code from classes, modules and forms (see below):

Option Explicit
Option Com         


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 06:32

    You can also try this code. It will preserve the items' filetypes (.bas, .cls, .frm) Remember to refer to / Check the Microsoft Visual Basic For Applications Extensibility Library in VBE > Tools > References

    Public Sub ExportAllCode()
    
        Dim c As VBComponent
        Dim Sfx As String
    
        For Each c In Application.VBE.VBProjects(1).VBComponents
            Select Case c.Type
                Case vbext_ct_ClassModule, vbext_ct_Document
                    Sfx = ".cls"
                Case vbext_ct_MSForm
                    Sfx = ".frm"
                Case vbext_ct_StdModule
                    Sfx = ".bas"
                Case Else
                    Sfx = ""
            End Select
    
            If Sfx <> "" Then
                c.Export _
                    Filename:=CurrentProject.Path & "\" & _
                    c.Name & Sfx
            End If
        Next c
    
    End Sub
    

提交回复
热议问题