3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

あるフォルダの中のxlsを開いて何かするマクロ

Last updated at Posted at 2015-05-20

    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


3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?