VBA 他シートへ関数の書き込み

開いているBook 間では,VBA の プロシャージャの書き込みもできるようです。

下記のプロシャージャでは,新しく開いたエクセルのファイルに,macro.txt に書かれた関数を書き込みます。

Private Sub CommandButton3_Click()
    'OPENしたBOOKのSHEET1に ”macro.txt” のプロしィージャを書き込む
    Dim wb As Workbook
    
    fTyp = "Excelファイル(*.xlsm),*.xlsm,Excelファイル(*.xlsx),*.xlsx,Excelファイル(*.xls),*.xls"
    prompt = "Excelファイルを選択してください"
    fPath = Application.GetOpenFilename(fTyp, , prompt)
    
    Set wb = Workbooks.Open(fPath, UpdateLinks:=Ture, ReadOnly:=Ture)
    
    With wb.VBProject.VBComponents("Sheet1").CodeModule
        .AddFromFile "C:\Users\mabo-2021\Desktop\****\*****\*****\*****\macro.txt"
    End With
    
End Sub

macro.txtという下記の内容のファイルを同じフォルダーにおいてきます。

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 Application.ScreenUpdating = True
End Sub