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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17551056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:04:50  来源:igfitidea点击:

PDF to Excel conversion putting each pdf page in a different worksheet

vbaexcel-vbapdf-conversionexcel

提问by Mike

I am attempting to convert a pdf file (with 16 pages) to an excel file in order to run a program I already have in place in excel. I have a code that converts the pdf to excel already, but I would like the macro to put each separate page of the pdf file in a different worksheet in my excel file( currently it copies all of the pages and pastes page 1 of the pdf into a worksheet).

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

All of the pages have the same heading if that helps at all. My current code is included below, thanks in advance.

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

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

采纳答案by Etienne Lepage-Lepitre

Try this. You should be able to make a loop and extract each pages of your PDF in different worksheet.

试试这个。您应该能够循环并在不同的工作表中提取 PDF 的每一页。