Skip to content

Instantly share code, notes, and snippets.

@m5knt
Last active December 27, 2022 08:00
Show Gist options
  • Save m5knt/b63ec4f24b195e3d6ebd1475e586c46b to your computer and use it in GitHub Desktop.
Save m5knt/b63ec4f24b195e3d6ebd1475e586c46b to your computer and use it in GitHub Desktop.
Import vba module
' 動作させる為には
' ファイル => オプション => セキュリティーセンター => セキュリティーセンターの設定
' マクロの設定 => "VBAプロジェクトオブジェクトモデルへのアクセスを信頼する" をチェック
Sub Hoge()
ImportModule ("Fuga")
Application.Run "Fuga.Fuga", "aa"
End Sub
Sub ImportModule(modname)
Dim abspath As String
abspath = ThisWorkbook.Path & "\" & modname & ".vba"
On Error GoTo REMOVEERROR
Set module = ThisWorkbook.VBProject.VBComponents(modname)
ThisWorkbook.VBProject.VBComponents.Remove module
REMOVEERROR:
ThisWorkbook.VBProject.VBComponents.IMPORT abspath
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment