Dim FilePath As String
Dim TargetFile As String
'開きたいファイルのパス
FilePath = "c:\hogehoge"
TargetFile = Dir(FilePath & "\*.xls", vbNormal)
Do Until TargetFile = ""
' 拡張子が3桁だと、xlsxやxlsmも拾ってしまうのでフィルタリング
If FilePath Like "*.xls" Then
Workbooks.Open FilePath & "\" & TargetFile
With Workbooks(TargetFile)
.Activate
' ファイルを開いてなんかやる
' 例えば
Dim i As Long
For i = 1 To .Worksheets.Count
' 全てのシートになんかやる
With .Worksheets(i)
.Select
' ここにやりたいこと
End With
Next
.Close
End With
End If
TargetFile = Dir()
DoEvents
Loop
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme