I have an ms access Application ( ms access 2013) and I'd like to export all vba code to separate files in a folder
What code can i add to do this?
Thanks,
I have an ms access Application ( ms access 2013) and I'd like to export all vba code to separate files in a folder
What code can i add to do this?
Thanks,
 
    
    Try this:
Public Sub ExportVBAComponents()
  Dim wbPath As String
  Dim vbComp As Object
  Dim exportPath As String
  wbPath = ActiveWorkbook.Path
  For Each vbComp In ActiveWorkbook.VBProject.VBComponents
    exportPath = wbPath & "\" & vbComp.Name & Format$(Now, "_yyyymmdd_hhnnss")
    Select Case vbComp.Type
        Case 1 ' Standard Module
            exportPath = exportPath & ".bas"
        Case 2 ' UserForm
            exportPath = exportPath & ".frm"
        Case 3 ' Class Module
            exportPath = exportPath & ".cls"
        Case Else ' Anything else
            exportPath = exportPath & ".bas"
    End Select
    On Error Resume Next
    vbComp.Export exportPath
    On Error GoTo 0
  Next
End Sub
The code above will export all the VBA components/modules in your ActiveWorkbook to the same location as your workbook. It will use the component name as part of the file name and will add a timestamp. Since you have more than 100 modules, you'd better change the export path to include a subfolder to group them all together in one place.
NOTE: For this to work, you need to select Options>Trust Center>Trust Center Settings...>Macro Settings>Trust access to the VBA project object model. Otherwise you get some random error in the For Each line. You can tick that option off afterwards if you're worried about it.
