|
こんばんは
もっと良い方法があるような気がしますが?
お試しを(すべてThisWorkbookのモジュールです)
Dim Ch As Long
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Ch = 2 Then
Call Wb_Open
End If
End Sub
Private Sub Workbook_Open()
Ch = 1
Call Wb_Open
Ch = 2
End Sub
Private Sub SheetAddandCopy(sFileName As Variant)
Dim Wb1 As Workbook
Set Wb1 = Workbooks.Open(ThisWorkbook.Path & "\" & sFileName, ReadOnly:=True)
Wb1.Worksheets(1).Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Workbooks(sFileName).Close False
Set Wb1 = Nothing
End Sub
Private Sub Wb_Open()
Dim Da As Variant, Co1 As Long
Application.ScreenUpdating = False
Co1 = 1
For Each Da In Array("Meibo.xls", "PrintForm.xls")
If Ch = 1 Then
SheetAddandCopy Da
Else
wb_Close Da, Co1
Co1 = 0
End If
Next Da
Ch = 3
Application.ScreenUpdating = True
End Sub
Private Sub wb_Close(sFileName As Variant, Co As Long)
Dim Wb1 As Workbook
Set Wb1 = Workbooks.Open(ThisWorkbook.Path & "\" & sFileName)
Application.DisplayAlerts = False
With ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count - Co)
.Cells.Copy Wb1.Worksheets(1).Range("A1")
.Delete
End With
Workbooks(sFileName).Close True
Application.DisplayAlerts = True
Set Wb1 = Nothing
End Sub
|
|