印刷マクロ

同じディレクトリに配置されたすべての xls ファイルのすべてのシートを印刷するVBAマクロ。ただし自分自身および "$" で始まるファイルは除く。
こういうのは、地味なようで意外と使えたりする。

Public Sub printAll()
    Dim fs As FileSystemObject
    Dim fld As Folder
    Dim f As File
    
    If MsgBox("印刷しますか?", _
            vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then
        Exit Sub
    End If
    
    Set fs = New FileSystemObject
    Set fld = fs.GetFolder(ThisWorkbook.path)
    
    For Each f In fld.Files
        If LCase$(Right$(f.Name, 4)) = ".xls" And _
                LCase$(Left$(f.Name, 1)) <> "$" And _
                f.Name <> ThisWorkbook.Name Then
            printSheets f.path
            Debug.Print f.Name
        End If
    Next
End Sub

Private Sub printSheets(path As String)
    Dim wb As Workbook
    
    Set wb = Workbooks.Open(path)
    wb.PrintOut
    wb.Close
End Sub