Hopefully someone can answer this problem for me.
I am trying to update a code module in Excel using the following code
My problem is with the highlighted line of code. It doesn't generate an error, it simply doesn't do anything!! Everything else in the procedure executes correctly, but the old module is not removed. This of course then creates errors with duplicate procedures in the file.
I have already checked that the module name is spelled exactly the same as the original.
Can anyone suggest what the problem might be?
Cheers
Lightning
I am trying to update a code module in Excel using the following code
Code:
Sub ReplaceModules()
' Export Module from this workbook
strFileName2 = ThisWorkbook.PATH & "\tempmodxxx.bas"
ThisWorkbook.VBProject.VBComponents("PublicSubprocedures").Export strFileName2
' Replace Module in UserBook
Set VBP = ActiveWorkbook.VBProject
Debug.Print ActiveWorkbook.Name
On Error GoTo ErrHandle
With VBP.VBComponents
[COLOR=red][b].Remove VBP.VBComponents("PublicSubprocedures")[/b][/color]
ActiveWorkbook.Save
.Import strFileName2
End With
Application.EnableEvents = False
ActiveWorkbook.Close savechanges:=True
Application.EnableEvents = True
' Delete the temorary module file
Kill strFileName2
' Workbooks(strFileName).Close savechanges:=True
MsgBox "The module has been replaced.", vbInformation
Exit Sub
ErrHandle:
' Did an error occur?
MsgBox Err.Number & ":" & Err.Description, vbCritical '"ERROR. The module may not have been replaced.",
I have already checked that the module name is spelled exactly the same as the original.
Can anyone suggest what the problem might be?
Cheers
Lightning