@@ -10,6 +10,8 @@ Option Compare Database
10
10
Option Private Module
11
11
Option Explicit
12
12
13
+ Private Const ModuleName = "modVCSUtility"
14
+
13
15
14
16
'---------------------------------------------------------------------------------------
15
17
' Procedure : GetAllContainers
@@ -577,3 +579,46 @@ Public Sub CompileAndSaveAllModules()
577
579
DoEvents
578
580
Perf.OperationEnd
579
581
End Sub
582
+
583
+
584
+ '---------------------------------------------------------------------------------------
585
+ ' Procedure : SaveAllModules
586
+ ' Author : Adam Waller
587
+ ' Date : 7/14/2021
588
+ ' Purpose : Loop through the VBE modules and classes, saving each one in Access.
589
+ '---------------------------------------------------------------------------------------
590
+ '
591
+ Public Sub SaveAllModules ()
592
+
593
+ Dim proj As VBProject
594
+ Dim cmp As VBComponent
595
+ Dim colNames As Collection
596
+ Dim varMod As Variant
597
+
598
+ If DebugMode(True ) Then On Error GoTo 0 Else On Error Resume Next
599
+
600
+ Set proj = GetVBProjectForCurrentDB
601
+ Set colNames = New Collection
602
+
603
+ ' Loop through and collect list of names.
604
+ ' (We can't save here, or we will get an error)
605
+ For Each cmp In proj.VBComponents
606
+ Select Case cmp.Type
607
+ Case vbext_ct_ClassModule, vbext_ct_StdModule
608
+ If (cmp.Saved = False ) Then colNames.Add cmp.Name
609
+ End Select
610
+ Next cmp
611
+
612
+ ' Set the active project to the CODE (add-in) project BEFORE
613
+ ' attempting to save the modules. Otherwise we will hit errors.
614
+ Set VBE.ActiveVBProject = GetCodeVBProject
615
+
616
+ ' Save each item in the list
617
+ For Each varMod In colNames
618
+ On Error GoTo 0
619
+ DoCmd.Save acModule, varMod
620
+ Next varMod
621
+
622
+ CatchAny eelError, "Error saving VBA modules" , ModuleName & ".SaveAllModules"
623
+
624
+ End Sub
0 commit comments