Dim masterBook As Workbook, targetBook As Workbook, tFile As String
Dim masterModule As String, targetModule As String
Dim masterSh As Worksheet
Const masterShName ="Sheet1"
tFile = "C:\test.xlsm"
Set masterBook = ThisWorkbook'¥³¥Ô¡¼¸µ
Set targetBook = Workbooks.Open(tFile)'¥³¥Ô¡¼Àè
'Sheet1 module¡¡¥³¡¼¥É¥³¥Ô¡¼
On Error GoTo er
Set masterSh = masterBook.Worksheets(masterShName)
masterModule = masterSh.CodeName
targetModule = targetBook.Worksheets(masterSh.Name).CodeName
Call moduleCopy(masterBook, targetBook, masterModule, targetModule)
er:
if err.number > 0 then
msgbox "¥¨¥é¡¼"
else
msgbox "¥³¥Ô¡¼½ªÎ»"
end if
Set masterBook = Nothing: Set targetBook = Nothing
End Sub
'//¥µ¥Ö¥×¥í¥°¥é¥à
Sub moduleCopy(masterBook As Workbook, targetBook As Workbook, masterModule As String, targetModule As String)
'¥³¥Ô¡¼¸µ¤Î¥â¥¸¥å¡¼¥ë¤Î¥³¡¼¥É¤ò¼èÆÀ
Dim VBP, Code As String
With masterBook.VBProject.VBComponents(masterModule).codemodule
Code = .Lines(1, .CountOfLines) 'Àë¸À¥»¥¯¥·¥ç¥ó¹þ
End With
'¥¿¡¼¥²¥Ã¥È¥â¥¸¥å¡¼¥ë¤Ë¥³¡¼¥É¤ò¥³¥Ô¡¼
With targetBook.VBProject.VBComponents(targetModule).codemodule
.DeleteLines 1, .CountOfLines '¥³¡¼¥ÉÁ´¤Æºï½ü
.AddFromString Code
End With
A¡ÁC¡Ê¤³¤ì¤Ï¡¢A¤Î¾ì¹ç¡Ë
B,C¤Ï¡¢¡Ö_A¡×¤ÎÉôʬ¤ò¤½¤ì¤¾¤ì¤ËÊѹ¹
¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö¡ö
Private Sub CommandButton2_Click()
If CheckSelect_A = True Then
CheckSelect_A = False
Else
CheckSelect_A = True
End If
If CheckSelect_A = True And CheckSelect_B = True And CheckSelect_C = True Then