EXCEL 我有1-100个工作表,按如下描述生成PDF?

发布网友 发布时间:2022-04-23 04:09

我来回答

2个回答

热心网友 时间:2023-10-14 09:30

需要引用Acrobat
Sub BatchMergePDF()

Dim s As Worksheet, start_index As Integer, index_end As Integer, strIn As String, temp_stname As Integer
Dim pdfFolder As String, pdfName As String, PageNum As Long
Dim sPDdoc As New Acrobat.AcroPDDoc, tPDdoc As New Acrobat.AcroPDDoc
strIn = InputBox("请输入要合并的范围" & vbCrLf & "例:要合并1-15页则输入1-15")

If Len(strIn) = 0 Then Exit Sub
If InStr(strIn, "-") = 0 Then Exit Sub

start_index = Mid(strIn, 1, InStr(strIn, "-") - 1)
index_end = Mid(strIn, InStr(strIn, "-") + 1)
strPath = ThisWorkbook.Path & "\"
For Each s In Sheets
If s.Name <> "Summary" Then
temp_stname = CInt(s.Name)
If temp_stname >= start_index And temp_stname <= index_end Then
s.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPath & s.Name & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
End If
Next

On Error Resume Next
Kill strPath + "合并.pdf"
On Error GoTo 0

pdfFolder = ThisWorkbook.Path & "\"
tPDdoc.Create
pdfName = Dir(pdfFolder)

Do While pdfName <> ""
If LCase(Mid(pdfName, Len(pdfName) - 2, 3)) = "pdf" Then
If sPDdoc.Open(pdfFolder & pdfName) Then
PageNum = sPDdoc.GetNumPages
tPDdoc.InsertPages tPDdoc.GetNumPages - 1, sPDdoc, 0, PageNum, 0
sPDdoc.Close
End If

Kill pdfFolder + pdfName
End If
pdfName = Dir
Loop

tPDdoc.Save PDSaveFull, pdfFolder & "合并.pdf"
tPDdoc.Close
Set sPDdoc = Nothing
Set tPDdoc = Nothing
MsgBox "完成"

End Sub

热心网友 时间:2023-10-14 09:30

Sub expdf()

s = InputBox("开始") * 1
e = InputBox("结束") * 1
ReDim ar(1 To e - s + 1)
For i = 1 To e - s + 1
ar(i) = i + s - 1
Next
ActiveWorkbook.Worksheets(ar()).Select
ActiveSheet.ExportAsFixedFormat xlTypePDF, "D:\" & s & "-" & e & ".pdf"
End Sub
这里是存在D盘,可根据需要自己修改。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com