I don't know the term for it (maybe self referencing) but I don't think you need to actually set a reference to the Applications Extensibility Library:
Code:
Sub ExportAllVBAModules()
'Late binding
Dim vbProj As Object
Dim vbComp As Object
Dim strFileName As String, strFilePath As String
Dim bExport As Boolean
strFilePath = strFilePath = Environ("USERPROFILE") & "\Documents\" 'Path to export to.
Set vbProj = ThisDocument.VBProject
For Each vbComp In vbProj.VBComponents
bExport = False
Select Case vbComp.Type
Case 1: strFileName = ReplaceInvalidChars(vbComp.Name) & ".bas": bExport = True
Case 2: strFileName = ReplaceInvalidChars(vbComp.Name) & ".cls": bExport = True
Case 3: strFileName = ReplaceInvalidChars(vbComp.Name) & ".frm": bExport = True
End Select
If bExport Then
strFileName = strFilePath & strFileName
vbComp.Export strFileName ' Export the component.
Debug.Print "Exported: " & vbComp.Name & " to " & strFileName
End If
Next vbComp
MsgBox "All VBA modules exported to: " & strFilePath, vbInformation, "Export Complete"
lbl_Exit:
Exit Sub
End Sub