以下のコードでVBAから、エクセルファイル内のモジュールをインポート/エクスポート(操作)できるかと思います。
だいぶ前(Microsoft Excel 12.0 Object Library)に試したものなので、
なにか変更されていたり、万が一実現できないときはご勘弁ください。
vba
1 '=================================================
2 'モジュールを追加
3 Dim tObj As Object, ExportPath As String
4 ExportPath = '任意のディレクトリパス'
5 For Each tObj In ThisWorkbook.VBProject.VBComponents
6 Select Case tObj.Type
7 Case STANDARD_MODULE
8 tObj.ExPort ExportPath & "\" & tObj.Name & ".bas"
9 Case CLASS_MODULE
10 tObj.ExPort ExportPath & "\" & tObj.Name & ".cls"
11 Case USER_FORM
12 tObj.ExPort ExportPath & "\" & tObj.Name & ".frm"
13 End Select
14 Next
15
16 ' モジュールを削除
17 '=================================================
18 Dim ComponentObj As Object
19 ModuleName = '任意のモジュール名'
20 For Each ComponentObj In ThisWorkbook.VBProject.VBComponents
21 If (ComponentObj.Type = 1 Or ComponentObj.Type = 2) _
22 And ComponentObj.Name = ModuleName Then
23 ' この標準モジュールを削除
24 ThisWorkbook.VBProject.VBComponents.Remove ComponentObj
25 Exit Sub
26 End If
27 Next ComponentObj
※少々不確定な情報かもしれませんが、1つも回答がついておらず、何かお役立ていただければと思い回答いたしました。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/18 22:04