vba - PDF 到 Excel 转换将每个 pdf 页面放在不同的工作表中

标签 vba excel pdf-conversion

我正在尝试将 pdf 文件(有 16 页)转换为 Excel 文件,以便运行 Excel 中已有的程序。我已经有一个将 pdf 转换为 excel 的代码,但我希望宏将 pdf 文件的每个单独页面放入我的 excel 文件中的不同工作表中(当前它复制所有页面并粘贴 pdf 的第 1 页)到工作表中)。

如果有帮助的话,所有页面都有相同的标题。我当前的代码包含在下面,提前致谢。

Private Sub CommandButton1_Click()
 'Declare Variable(s)
Dim appAA As Acrobat.CAcroApp, docPDF As Acrobat.CAcroPDDoc
Dim strFileName As String, intNOP As Integer, arrI As Variant
Dim intC As Integer, intR As Integer, intBeg As Integer, intEnd As Integer

'Initialize Variables
Set appAA = CreateObject("AcroExch.App"): Set docPDF = CreateObject("AcroExch.PDDoc")

'Set PDF FileName  
strFileName = "C:\Documents and Settings\Michael Palkovitz\My Documents\Test\EC Operations Budget February FY13.pdf"

'Read PDF File
docPDF.Open (strFileName)

'Extract Number of Pages From PDF File
intNOP = docPDF.GetNumPages

'Select First Data Cell
Range("A1").Select

'Open PDF File
ActiveWorkbook.FollowHyperlink strFileName, , True

'Loop Through All PDF File Pages
For intC = 1 To intNOP
'Go To Page Number
SendKeys ("+^n" & intC & "{ENTER}")

'Select All Data In The PDF File's Active Page
SendKeys ("^a"), True

'Right-Click Mouse
SendKeys ("+{F10}"), True

'Copy Data As Table
SendKeys ("c"), True

'Minimize Adobe Window
SendKeys ("%n"), True

'Paste Data In This Workbook's Worksheet
ActiveSheet.Paste

'Select Next Paste Cell
Range("A" & Range("A1").SpecialCells(xlLastCell).Row + 2).Select

'Maximize Adobe Window
SendKeys ("%x")
Next intC

'Close Adobe File and Window
SendKeys ("^w"), True

'Empty Object Variables
Set appAA = Nothing: Set docPDF = Nothing

'Select First Cell
Range("A1").Select
end sub

最佳答案

尝试this 。您应该能够进行循环并将 PDF 的每个页面提取到不同的工作表中。

关于vba - PDF 到 Excel 转换将每个 pdf 页面放在不同的工作表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17551056/

相关文章:

javascript - 使用javascript将PDF转换为DOM

excel - 根据特定单元格值清除 Excel 表格中的列内容

excel - 我应该如何在 VBA Excel 中为相同的对象使用 1 个代码

html - Excel VBA提取href值

excel - 在 Excel 中计算电力塔的困难

c# - 办公文件转PDF

vba - 使用命令按钮 VBA 的奇怪删除行为

HTTP 请求的 VBA 代理自动配置

excel - 将数据从第 2 行复制到一张纸上的最后一行数据并粘贴到另一张纸的第一个空行的 VBA 代码