mikechambers
Active Member
- Joined
- Apr 27, 2006
- Messages
- 397
I have the following code in Workbook C to perform the following steps:
1. Export Module1 to a BAS file from Workbook A
2. Delete Module1 from Workbook B
3. Import BAS file into Workbook B as Module1
Code:
Dim FName As String, vbCom As Object
With Workbooks("Workbook A.xls")
FName = "C:\code.bas"
.VBProject.VBComponents("Module1").Export FName
End With
Set vbCom = Workbooks("Workbook B.xls").VBProject.VBComponents
vbCom.Remove VBComponent:=vbCom.Item("Module1")
vbCom.Import FName
Kill FName
The problem is after the Remove line, Module1 still shows up in Workbook B, so that when it imports FName, it does so as Module11. BUT, if I end the macro after the remove line, Module1 disappears. So it seems like a refresh issue or something. It is not actually removed until the macro is finished running? Does that make sense? I tried Application.Screenupdating=True after the Remove line, but didn't fix it. Any ideas???
1. Export Module1 to a BAS file from Workbook A
2. Delete Module1 from Workbook B
3. Import BAS file into Workbook B as Module1
Code:
Dim FName As String, vbCom As Object
With Workbooks("Workbook A.xls")
FName = "C:\code.bas"
.VBProject.VBComponents("Module1").Export FName
End With
Set vbCom = Workbooks("Workbook B.xls").VBProject.VBComponents
vbCom.Remove VBComponent:=vbCom.Item("Module1")
vbCom.Import FName
Kill FName
The problem is after the Remove line, Module1 still shows up in Workbook B, so that when it imports FName, it does so as Module11. BUT, if I end the macro after the remove line, Module1 disappears. So it seems like a refresh issue or something. It is not actually removed until the macro is finished running? Does that make sense? I tried Application.Screenupdating=True after the Remove line, but didn't fix it. Any ideas???