Hello,
I have an addin that creates mulitple reports and since each of the report modules are updated by a different person, I have code that will delete the old module and import the new one for each one of the reports.
The process goes as follows:
Any ideas?
Is vba getting ahead of itself?
My code is below.
I have an addin that creates mulitple reports and since each of the report modules are updated by a different person, I have code that will delete the old module and import the new one for each one of the reports.
The process goes as follows:
- Delete each of the old modules.
- Import the new modules.
- Here is where the issue is. When each of the new modules are imported, a "1" is added to the end and I end up having to run another macro "RenameModules" to rename the modules. I understand that a "1" would be added if I am importing another module with the same name.
Any ideas?
Is vba getting ahead of itself?
My code is below.
Code:
Public Const strMod2Loc = "C:\UpdatedModules\Mod2.bas"
Public Const strMod3Loc = "C:\UpdatedModules\Mod3.bas"
Public Const strMod4Loc = "C:\UpdatedModules\Mod4.bas"
Public Const strMod5Loc = "C:\UpdatedModules\Mod5.bas"
Public Const strMod6Loc = "C:\UpdatedModules\Mod6.bas"
Public Const strMod2Name = "Mod2"
Public Const strMod3Name = "Mod3"
Public Const strMod4Name = "Mod4"
Public Const strMod5Name = "Mod5"
Public Const strMod6Name = "Mod6"
Sub UpdateModules()
ThisWorkbook.VBProject.VBComponents.Remove ThisWorkbook.VBProject.VBComponents(strMod2Name)
ThisWorkbook.VBProject.VBComponents.Remove ThisWorkbook.VBProject.VBComponents(strMod3Name)
ThisWorkbook.VBProject.VBComponents.Remove ThisWorkbook.VBProject.VBComponents(strMod4Name)
ThisWorkbook.VBProject.VBComponents.Remove ThisWorkbook.VBProject.VBComponents(strMod4Name)
ThisWorkbook.VBProject.VBComponents.Remove ThisWorkbook.VBProject.VBComponents(strMod6Name)
InsertModule ThisWorkbook, strMod2Loc
InsertModule ThisWorkbook, strMod3Loc
InsertModule ThisWorkbook, strMod4Loc
InsertModule ThisWorkbook, strMod5Loc
InsertModule ThisWorkbook, strMod6Loc
End Sub
Sub RenameModules()
On Error Resume Next
ThisWorkbook.VBProject.VBComponents("Mod21").Name = "Mod2"
ThisWorkbook.VBProject.VBComponents("Mod31").Name = "Mod3"
ThisWorkbook.VBProject.VBComponents("Mod41").Name = "Mod4"
ThisWorkbook.VBProject.VBComponents("Mod51").Name = "Mod5"
ThisWorkbook.VBProject.VBComponents("Mod61").Name = "Mod6"
On Error GoTo 0
End Sub