欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

批量将EXCEL转为PDF

程序员文章站 2023-12-25 18:22:21
...

通过vba将excle批量转为pdf

Sub EXCELtoPDF()

    Dim MyPath As String, MyName As String
    
    Dim isPrintHideSheet

    MyPath = ThisWorkbook.Path & "\"

    MyName = Dir(MyPath & "*.xls") '将需要打印的表格放在代码表格同目录下,取文件名
    
    isPrintHideSheet = Range("H12") '需根据实际修改

    Application.ScreenUpdating = False

    Do While MyName <> ""

        If MyName <> ThisWorkbook.Name Then

            Set wb = GetObject(MyPath & MyName) 'getobject隐式打开excel
        
            If isPrintHideSheet >= 1 Then

               For i = 1 To wb.Worksheets.Count

                   wb.Worksheets(i).Visible = 1 '显示隐藏的worksheet

               Next
            End If

            wb.ExportAsFixedFormat Type:=xlTypePDF, Filename:=MyPath & MyName & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

            wb.Close False

            Set wb = Nothing

        End If

        MyName = Dir

    Loop

    Application.ScreenUpdating = True

    MsgBox "转换完毕"

End Sub

效果图
批量将EXCEL转为PDF

相关标签: excel

上一篇:

下一篇: