Skip to content

Instantly share code, notes, and snippets.

@toagit
Created August 1, 2016 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toagit/4561c2813bccf39aef0e2256822f3905 to your computer and use it in GitHub Desktop.
Save toagit/4561c2813bccf39aef0e2256822f3905 to your computer and use it in GitHub Desktop.
vbaプロジェクトの全てのモジュールをエクスポートする
'全モジュールエクスポート
'
'Excelの設定を以下の通りに変更すること
'1)オプション -> セキュリティーセンター -> [セキュリティーセンターの設定]ボタン押下
'2)マクロ設定(左ペイン) -> [VBAプロジェクトオブジェクトモデルへのアクセスを信頼する] チェックON
Public Sub ExportAllModule()
Dim destDir As String
With CreateObject("WScript.Shell")
destDir = .SpecialFolders("Desktop") & "\modules"
End With
If Dir(destDir, vbDirectory) = "" Then
Call MkDir(destDir)
End If
With ActiveWorkbook.VBProject
Const vbext_ct_StdModule As Variant = 1
Const vbext_ct_MSForm As Variant = 2
Const vbext_ct_ClassModule As Variant = 3
Dim ext As String
Dim c As Object
For Each c In .VBComponents
Select Case c.Type
Case vbext_ct_StdModule
ext = ".bas"
Case vbext_ct_MSForm
ext = ".frm"
Case vbext_ct_ClassModule
ext = ".cls"
Case Else
ext = Empty
End Select
If ext <> Empty Then
Call c.Export(destDir & "\" & c.Name & ext)
End If
Next
End With
MsgBox "モジュールのエクスポートを完了しました。" & vbNewLine & destDir
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment