<説明>
このVBSの上にExcelファイルをドラッグドロップすると、そのExcelファイル内のVBAコードがExportされる。
あらかじめ、Excelのオプションの「VBAプロジェクトオブジェクトモデルへのアクセルを信頼する」にチェックを入れておく必要がある。
ExportVBA.vbs
Option Explicit
Dim a 'Argument
Dim b 'Book
Dim c 'Component
Dim d 'Directory
Dim e 'Excel
Dim f 'FileSystemObject
With WScript
If .Arguments.Count = 0 Then
.Echo "Drop your Excel Macro Files on it."
Else
Set f = CreateObject("Scripting.FileSystemObject")
Set e = CreateObject("Excel.Application")
For Each a In .Arguments
If f.FileExists(a) Then
d = f.GetParentFolderName(.ScriptFullName) & "\vba_" & f.GetFileName(a)
Set b = e.Workbooks.Open(a,0,True,,,,True)
With b.VBProject
If .Protection = 0 Then
For Each c In .VBComponents
If c.CodeModule.CountOfLines > 2 Then
If Not f.FolderExists(d) And Not f.FileExists(d) Then f.CreateFolder d
c.Export d & "\" & c.Name & Ext(c.Type)
End If
Next
End If
End With
b.Close False
End If
Next
e.Quit
Set b = Nothing
Set e = Nothing
Set f = Nothing
End If
End With
Function Ext(cType)
Select Case cType
Case 1 : Ext = ".bas"
Case 3 : Ext = ".frm"
Case Else : Ext = ".cls"
End Select
End Function