excel 批量打印word、excel所有sheet 的 vba代码

excel 批量打印word、excel所有sheet 的 vba代码_第1张图片

 可以拉几个按钮用。

Sub 批量打印WORD文档()
     Dim fileToOpen, GetOpenFilename, App, iFile
     fileToOpen = Application.GetOpenFilename(filefilter:="Word文档(*.do*),*.do*", FilterIndex:=4, Title:="请选择要处理的文档(可多选)", MultiSelect:=True)
     If Not IsArray(fileToOpen) Then

        MsgBox "你没有选择文件", vbOKOnly, "提示": Exit Sub

     Else: Set App = CreateObject("Word.Application")
         For Each iFile In fileToOpen
             Set WrdDoc = App.Documents.Open(iFile)
             App.Documents(WrdDoc).PrintOut
             App.Documents(WrdDoc).Close False
             T = T + 1
         Next
     End If
     MsgBox "操作完成!!" & vbCrLf & "打印了 " & T & " 个文件。", vbOKOnly, "提示"
End Sub

Sub 批量打印Excel文档()
    Dim fileToOpen, App, Wbk
    fileToOpen = Application.GetOpenFilename(filefilter:="Excel文档(*.xl*),*.xl*", FilterIndex:=4, Title:="请选择要处理的文档(可多选)", MultiSelect:=True)
    If Not IsArray(fileToOpen) Then
        MsgBox "你没有选择文件", vbOKOnly, "提示"
        Exit Sub
    Else
        Set App = CreateObject("Excel.Application")
        For Each iFile In fileToOpen
            Set Wbk = App.Workbooks.Open(iFile)
            For Each Wsh In Wbk.Worksheets
                Wsh.PrintOut Preview:=False
            Next
            Wbk.Close False
            T = T + 1
        Next
    End If
    MsgBox "操作完成!" & vbCrLf & "打印了 " & T & " 个文件。", vbOKOnly, "提示"
End Sub
Sub 批量打印PDF文档()
    Dim filePaths As String
    filePaths = ""

    '选择多个pdf文件
    Dim fileToOpen As Variant
    fileToOpen = Application.GetOpenFilename(filefilter:="PDF文档(*.pdf),*.pdf", FilterIndex:=4, Title:="请选择要处理的文档(可多选)", MultiSelect:=True)
    If Not IsArray(fileToOpen) Then
        MsgBox "你没有选择文件", vbOKOnly, "提示"
        Exit Sub
    Else
        For Each filePath In fileToOpen
                Dim cmd As String
                cmd = "cmd /c start " & filePath
                Call Shell(cmd, vbHide)
        Next
    End If
End Sub

你可能感兴趣的:(excel,word,powerpoint)