excel - 将 PDF 拆分为每页的新文件 - Excel VBA
问题描述
我正在尝试将 pdf 每页拆分为多个新文件。我在Excel 论坛上找到了这段代码, 我将其修改为适合我的文件夹路径和文件。我还将 Acrobat.tdl 库添加到引用中。(没有安装实际的 acrobat pro。按照此链接中建议的步骤操作)
但是,当我尝试运行代码时,出现错误 - 运行时错误“429”:ActiveX 组件无法创建对象。错误发生在线路上Set PDDoc = CreateObject("AcroExch.pdDoc")
这是完整的代码:
Sub SplitPDF()
Dim PDDoc As Acrobat.CAcroPDDoc, newPDF As Acrobat.CAcroPDDoc
Dim PDPage As Acrobat.CAcroPDPage
Dim thePDF As String, PNum As Long
Dim f As String, i As Integer, Result As Variant, NewName As String
f = ThisWorkbook.Path & "\"
thePDF = f & "CDE_9740240D_2020-09-08.pdf"
Set PDDoc = CreateObject("AcroExch.pdDoc")
Result = PDDoc.Open(thePDF)
If Not Result Then
MsgBox "Can't open file: " & thePDF
Exit Sub
End If
'...
PNum = PDDoc.GetNumPages
For i = 0 To PNum - 1
Set newPDF = CreateObject("AcroExch.pdDoc")
newPDF.Create
NewName = f & " Page_" & i & "_of_" & PNum & ".pdf"
newPDF.InsertPages -1, PDDoc, i, 1, 0
newPDF.Save 1, NewName
newPDF.Close
Set newPDF = Nothing
Next i
End Sub
有人可以帮我使这个代码工作。
解决方案
推荐阅读
- java - 工厂设计模式与OCP(开闭原则)的违反
- mysql - "(" 在此位置无效,需要 EOF,";"
- composer-php - 作曲家,显示建议的包
- android - 我在哪里可以将构建操作设置为“AndroidResource”?
- javascript - 如何在用逗号分隔值的键分隔的数组中排序
- python - TypeError: func() missing 1 required positional argument 'n' leetcode
- node.js - 使用 AWS 生成的凭证连接到 RDS Postgres 时密码验证失败
- python - OpenCV 使用蒙版图像去除背景
- python - 在 Python 中按名称/ID 获取存储驱动器的驱动器号
- angular - 如何从组件中抛出 url 然后将其设置为新的服务 url?