2013-07-09 30 views
5

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

如果有帮助的话,所有页面都有相同的标题。我目前的代码包含在下面,预先感谢。

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 

回答

1

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

+0

感谢您的帮助...代码运行时没有错误,但打开PDF后..我得到“文件名,目录名或卷标语法不正确”message.my pdf文件路径如下 PDFPath = ThisWorkbook.Path&“\”&“C:\ Documents and Settings \ Michael Palkovitz \ My Documents \ Test \ EC Operations Budget February FY13.pdf” – Mike

+0

更新..我得到您的代码以打开文档,只需要让它复制和粘贴。 – Mike

+0

得到了复制和粘贴,感谢您的帮助 – Mike