本文主要是介绍EXCEL VBA 多sheet批量转转PDF,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
EXCEL VBA 多sheet批量转转PDF
Sub zhuanpdf()
'转pdfApplication.ScreenUpdating = False '关闭刷新Dim chaifm As String '拆分名chaifm = Sheets("参数表").Cells(75, 2).ValueDim yuanbm As String '原表名Dim ws As Worksheet '定义表格Dim biao As String '表名Dim biao2 As String '辅助记数,有与否yuanbm = ActiveSheet.Namebiao = ""biao2 = ""On Error Resume NextSet ws = Nothing'第一个表If Sheets("参数表").Cells(5, 2).Value = True And Sheets("参数表").Cells(8, 2).Value <> "" Thenbiao = Sheets("参数表").Cells(8, 2).ValueSet ws = Sheets(biao)If ws Is Nothing Then '指定的工作表不存在Else '指定的工作表已存在Sheets(biao).Activatebiao2 = biaoSet ws = NothingEnd IfEnd If'第二个表If Sheets("参数表").Cells(6, 2).Value = True And Sheets("参数表").Cells(9, 2).Value <> "" Thenbiao = Sheets("参数表").Cells(9, 2).ValueSet ws = Sheets(biao)If ws Is Nothing Then '指定的工作表不存在Else '指定的工作表已存在If biao2 = "" ThenSheets(biao).ActivateElseSheets(biao).Select Replace:=FalseEnd Ifbiao2 = biaoSet ws = NothingEnd IfEnd If'第三个表If Sheets("参数表").Cells(7, 2).Value = True And Sheets("参数表").Cells(10, 2).Value <> "" ThenDim biaochuan As String '表串,即多个工作表,用“/”分开Dim iii As Integerbiaochuan = Sheets("参数表").Cells(10, 2).Valueiii = 1Do While iii <> 100iii = InStr(1, biaochuan, "/", 0)If iii = 0 Theniii = 100biao = biaochuanElsebiao = Left(biaochuan, iii - 1)biaochuan = Mid(biaochuan, iii + 1, 300)End IfSet ws = Sheets(biao)If ws Is Nothing Then '指定的工作表不存在Else '指定的工作表已存在If biao2 = "" ThenSheets(biao).ActivateElseSheets(biao).Select Replace:=FalseEnd Ifbiao2 = biaoSet ws = NothingEnd IfLoopEnd If'生成pdfCall zhuanpdf2(chaifm)
On Error GoTo 0
Sheets(yuanbm).Select
Application.ScreenUpdating = True '开启刷新End Sub
Sub zhuanpdf2(chaifm As String)
'转pdf2luj = ThisWorkbook.PathIf Dir(luj & "\拆分表", vbDirectory) = Empty ThenMkDir luj & "\拆分表"End Ifluj = luj & "\拆分表\"ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _luj & chaifm & ".pdf", Quality:=xlQualityStandard, _IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _False
End Sub
这篇关于EXCEL VBA 多sheet批量转转PDF的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!