我在网上发现了一些用于打开PDF的代码,但是当我导入我的PDF时,我似乎无法在目标表单中打开它" Current"。我无法看到我的变量有什么问题,但它没有选择Current作为活动表。任何帮助将不胜感激。
Sub OpenPDF()
Dim wkb As Workbook
Dim IandC As Worksheet, Comparison As Worksheet, Previous As Worksheet, Current As Worksheet, Flows As Worksheet
Dim appAA As Acrobat.AcroApp, 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
Dim CurrentCell As Range
Set wkb = Application.ActiveWorkbook
Set IandC = wkb.Sheets("Instructions and CrossRef")
Set Comparison = wkb.Sheets("Comparison")
Set Previous = wkb.Sheets("Previous")
Set Current = wkb.Sheets("Current")
Set Flows = wkb.Sheets("Flows")
'Get Current Sheet
'Initialize Variables
Set Current = Application.ActiveSheet
With IandC
Set CurrentCell = Range("L1")
End With
strFileName = "G:\CCLFG\IRG\FG\Cashflows\MPI Flows\" & CurrentCell & ".pdf"
'Select First Data Cell
Current.Range("A1").Select
Set appAA = CreateObject("AcroExch.App"): Set docPDF = CreateObject("AcroExch.PDDoc")
docPDF.Open (strFileName)
'Extract Number of Pages From PDF File
intNOP = docPDF.GetNumPages
'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
Current.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
Current.Range("A1").Select
End Sub