staticbob
Well-known Member
- Joined
- Oct 7, 2003
- Messages
- 1,079
Guys,
I am using this code to transfer code from one workbook to another. I need to upgrade 3 forms and 2 modules. How do I loop through these. AND, ensure that the modules and forms in the target workbook are overwritten or deleted first.
The Application.Dialogs(xlDialogActivate).Show line is not making the workbook selected active ???
I need to upgrade - frmsavewr, frmsavecr, Mdl_Sendmail, Md_spellcheck, Mdl_Toolbar.
Thanks in advance !
Bob
EDIT - I have now figured out that I need to delete the modules from the target workbook first, I've added code to do this.
I am using this code to transfer code from one workbook to another. I need to upgrade 3 forms and 2 modules. How do I loop through these. AND, ensure that the modules and forms in the target workbook are overwritten or deleted first.
The Application.Dialogs(xlDialogActivate).Show line is not making the workbook selected active ???
I need to upgrade - frmsavewr, frmsavecr, Mdl_Sendmail, Md_spellcheck, Mdl_Toolbar.
Thanks in advance !
Bob
EDIT - I have now figured out that I need to delete the modules from the target workbook first, I've added code to do this.
Code:
Private Sub upgrade()
'Select target workbook
Dim TWB As Workbook 'Target Workbook
Dim UWB As Workbook 'Upgrade Workbook
Dim FName As String 'temp filename for export / import
Application.ScreenUpdating = False
Set UWB = ActiveWorkbook
MsgBox "Please select the Workbook to upgrade" & vbNewLine & "from the following list . . ." & vbNewLine & "(Click OK to show)"
Application.Dialogs(xlDialogActivate).Show
Set TWB = ActiveWorkbook
'delete existing modules in Target WB
Dim VBComp As VBComponent
On Error Resume Next
With TWB
Set VBComp = ThisWorkbook.VBProject.VBComponents("frmsavewr")
ThisWorkbook.VBProject.VBComponents.Remove VBComp
Set VBComp = ThisWorkbook.VBProject.VBComponents("frmsavecr")
ThisWorkbook.VBProject.VBComponents.Remove VBComp
Set VBComp = ThisWorkbook.VBProject.VBComponents("Mdl_Sendmail")
ThisWorkbook.VBProject.VBComponents.Remove VBComp
Set VBComp = ThisWorkbook.VBProject.VBComponents("Mdl_spellcheck")
ThisWorkbook.VBProject.VBComponents.Remove VBComp
Set VBComp = ThisWorkbook.VBProject.VBComponents("Mdl_Toolbar")
ThisWorkbook.VBProject.VBComponents.Remove VBComp
End With
'import / export code
With UWB
FName = .Path & "\code.txt"
.VBProject.VBComponents("frmsavewr").Export FName
End With
TWB.VBProject.VBComponents.Import FName
With UWB
FName = .Path & "\code.txt"
.VBProject.VBComponents("frmsavecr").Export FName
End With
TWB.VBProject.VBComponents.Import FName
With UWB
FName = .Path & "\code.txt"
.VBProject.VBComponents("Mdl_Sendmail").Export FName
End With
TWB.VBProject.VBComponents.Import FName
With UWB
FName = .Path & "\code.txt"
.VBProject.VBComponents("Mdl_spellcheck").Export FName
End With
TWB.VBProject.VBComponents.Import FName
With UWB
FName = .Path & "\code.txt"
.VBProject.VBComponents("Mdl_Toolbar").Export FName
End With
TWB.VBProject.VBComponents.Import FName
Application.ScreenUpdating = True
End Sub