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

 可以拉几个按钮用。

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

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
Excel VBA中实现批量提取Word表格内容可以通过以下步骤进行: 1.首先,在Excel的工作簿中打开Visual Basic Editor(VBE)。 2.在VBE的工具栏上,选择“插入”→“模块”,在模块中编写VBA代码。 3.在编写代码之前,确保已经添加对Microsoft Word对象库的引用。可以通过在VBE中选择“工具”→“引用”来添加引用。 4.在VBA代码的模块中,使用Word对象变量来打开Word文档。例如,可以使用以下代码打开一个名为"Document1.docx"的Word文档: ``` Dim wdApp As Word.Application Dim wdDoc As Word.Document Set wdApp = New Word.Application Set wdDoc = wdApp.Documents.Open("C:\路径\Document1.docx") wdApp.Visible = True ``` 5.接下来,使用“With”语句和对象变量来引用Word文档中的表格,然后遍历表格中的每个单元格,并将其值复制到Excel工作表中。 ``` With wdDoc For Each tbl In .Tables For Each cell In tbl.Range.Cells '将单元格值复制到Excel工作表中的指定位置 Worksheets("Sheet1").Cells(rowNum, colNum).Value = cell.Range.Text '更新行号和列号 rowNum = rowNum + 1 colNum = colNum + 1 Next cell Next tbl End With ``` 6.在代码结束时,记得关闭Word文档和应用程序对象。 ``` wdDoc.Close wdApp.Quit Set wdDoc = Nothing Set wdApp = Nothing ``` 以上步骤将通过Excel VBA实现一键批量提取Word表格内容。可以根据具体需求进行适当的修改和调整,如指定目标表格的位置、添加错误处理等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值