|
参考
ht tp://www.vbalab.net/vbaqa/c-board.cgi?cmd=ntr;tree=53177;id=excel
フォームの場合
fpas = ThisWorkbook.Path
ThisWorkbook.VBProject.VBComponents("UserForm1").Export ("UserForm1.frm")
Workbooks("Book1.xls").VBProject.VBComponents.Import (fpas & "\UserForm1.frm")
With ThisWorkbook
.VBProject.VBComponents.Item("Module1").Export Filename:="C:\xxxx\Module1.bas"
'C:\xxxxに標準モジュールをエクスポートします。
.VBProject.VBComponents.Item("UserForm1").Export Filename:="C:\xxxx\UserForm1.frm"
'C:\xxxxにユーザーフォームをエクスポートします。
End With
///////////////
Sub インポート()
Dim FileNM As Variant, ブック名 As String, pat As String
ブック名 = "Book2.xls"
pat = ThisWorkbook.Path
For Each FileNM In CreateObject("Scripting.FileSystemObject").GetFolder(pat).Files
If Right(FileNM.Name, 3) = "bas" Or Right(FileNM.Name, 3) = "frm" Then
Workbooks(ブック名).VBProject.VBComponents.Import (FileNM)
End If
Next
End Sub
Sub エクスポート()
Dim obj As Object, pat As String
pat = ThisWorkbook.Path
With Workbooks("フォーム、モジュール抜き出しファイル.xls")
For Each obj In .VBProject.VBComponents
If obj.Type = 1 Then
obj.Export Filename:=pat & "\" & obj.Name & ".bas"
ElseIf obj.Type = 1 Or obj.Type = 3 Then
obj.Export Filename:=pat & "\" & obj.Name & ".frm"
End If
Next
End With
End Sub
|
|