1

すべてのシートを 1 つの Excel ファイルから別の Excel ファイルにコピーするコードがありますが、1 つのシートしかなく、コピーするときに元のシートを sheet1 (2) として宛先ファイルに貼り付けます。

目的のファイルの sheet1 に sheet1 の直後に新しいシートを作成しないようにコードが必要です

遊んでみましたが取れませんでした

ありがとう

Sub CopySheets()

Dim WB As Workbook
Dim SourceWB As Workbook
Dim WS As Worksheet
Dim ASheet As Worksheet

'Turns off screenupdating and events:
Application.ScreenUpdating = False
Application.EnableEvents = False

 'Sets the variables:
 Set WB = ActiveWorkbook
 Set ASheet = ActiveSheet
 Set SourceWB = Workbooks.Open(WB.Path & "\MyOtherWorkbook.xls")  'Modify to match

'Copies each sheet of the SourceWB to the end of original wb:
For Each WS In SourceWB.Worksheets
    WS.Copy after:=WB.Sheets(WB.Sheets.Count)
Next WS

    SourceWB.Close savechanges:=False
    Set WS = Nothing
    Set SourceWB = Nothing

WB.Activate
ASheet.Select
    Set ASheet = Nothing
    Set WB = Nothing

Application.EnableEvents = True

End Sub
4

1 に答える 1