Option Explicit
Sub moveCode()
ImpExpForm.Show
End Sub
Option Explicit
Private Sub ComboWB_Change()
Dim i As Integer
ListVBE.Clear
With Workbooks(ComboWB.ListIndex + 1).VBProject.VBComponents
For i = 1 To Workbooks(ComboWB.ListIndex + 1).VBProject.VBComponents.Count
ListVBE.AddItem .Item(i).Name
If .Item(i).Type = 2 Then
ListVBE.List(ListVBE.ListCount - 1, 1) = "class module"
ElseIf .Item(i).Type = 100 Then
ListVBE.List(ListVBE.ListCount - 1, 1) = "sheet / document / file"
ElseIf .Item(i).Type = 3 Then
ListVBE.List(ListVBE.ListCount - 1, 1) = "userform"
ElseIf .Item(i).Type = 1 Then
ListVBE.List(ListVBE.ListCount - 1, 1) = "standard module"
Else
ListVBE.List(ListVBE.ListCount - 1, 1) = "unknown"
End If
Next i
End With
End Sub
Private Sub CommandExport_Click()
Dim fileName As Variant
fileName = Application.GetSaveAsFilename("vbcomponent")
If fileName <> False Then
On Error GoTo ExpError
Workbooks(ComboWB.ListIndex + 1).VBProject.VBComponents(ListVBE.ListIndex + 1).Export (fileName)
On Error GoTo 0
MsgBox "VBE Component '" & ComboWB.List(ComboWB.ListIndex) & "' exported to:" & Chr(13) & fileName
End If
Exit Sub
ExpError:
MsgBox "Could not export '" & ComboWB.List(ComboWB.ListIndex) & "' to:" & Chr(13) & fileName
On Error GoTo 0
Exit Sub
End Sub
Private Sub CommandImport_Click()
Dim fileName As Variant
fileName = Application.GetOpenFilename()
If fileName <> False Then
On Error GoTo ImpError
Workbooks(ComboWB.ListIndex + 1).VBProject.VBComponents.Import (fileName)
On Error GoTo 0
MsgBox "VBE Component:" & Chr(13) & "'" & fileName & "' imported to:" & Chr(13) & ComboWB.List(ComboWB.ListIndex)
End If
Exit Sub
ImpError:
MsgBox "Could not import " & Chr(13) & "'" & fileName & "' to:" & Chr(13) & ComboWB.List(ComboWB.ListIndex)
On Error GoTo 0
Exit Sub
End Sub
Private Sub CommandOK_Click()
Unload Me
End Sub
Private Sub ListVBE_Click()
With ListVBE
If .List(.ListIndex, 1) = "standard module" Or .List(.ListIndex, 1) = "userform" Or .List(.ListIndex, 1) = "class module" Then
CommandExport.Enabled = True
Else
CommandExport.Enabled = False
End If
End With
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer
For i = 1 To Workbooks.Count
ComboWB.AddItem Workbooks(i).Name
Next i
ComboWB.ListIndex = 0
Me.Zoom = 120
Me.Width = 1.2 * Me.Width
Me.Height = 1.2 * Me.Height
End Sub
|