Hi,

I have a subroutine to copy a module, "Module 2", from book1 to book2. The code is as follows:

Dim FName As String

With Workbooks("book1.xls")
FName = .Path & "\code.txt"
.VBProject.VBComponents("Module2").Export FName
End With

Workbooks("book2.xls").VBProject.VBComponents.Import FName

Whenever I try to add the subroutine code to book1 and try to save book1, book1 gets closed and therefore it cannot be saved. The error message is "The document was successfully saved, but Excel cannot re-open it because of a sharing violation".

I've found out that it's the last line of code
"Workbooks("book2.xls").VBProject.VBComponents.Import FName" that causes this problem.

Does anyone have an idea of why this is happening and possibly have a solution?

Thanks so much!

Regards,
-ctg