|
▼はるな さん:
Sub Sample2()
Dim myPath As String
Dim workWB As Workbook
Dim fsoFile As Object
Dim Fso As Object
Dim xlApp As Excel.Application
myPath = "C:\Test" '<== 実際のフォルダ名に
Set xlApp = New Excel.Application
Set Fso = CreateObject("Scripting.FileSystemObject")
For Each fsoFile In Fso.GetFolder(myPath).Files
If LCase(Fso.GetExtensionName(fsoFile.Name)) = "xls" Then
Set workWB = xlApp.Workbooks.Open(Filename:=myPath & "\" & fsoFile.Name)
If Not IsError(xlApp.Evaluate("[" & workWB.Name & "]管理シート上期!A1")) Then
workWB.Sheets("管理シート上期").Copy After:=workWB.Sheets("管理シート上期")
With workWB.ActiveSheet
If IsError(xlApp.Evaluate("[" & workWB.Name & "]下期!A1")) Then .Name = "下期"
.Cells.ClearContents 'もし内容のクリアがだめならカットしてください
End With
xlApp.DisplayAlerts = False
workWB.SaveAs myPath & "\" & workWB.Name & "_下期.xls"
workWB.Close
xlApp.DisplayAlerts = True
End If
End If
Next
xlApp.Quit
MsgBox "処理が終了しました"
End Sub
|
|