【发布时间】:2018-02-01 19:32:25
【问题描述】:
我有一个工作代码可以将数据从 pdf 传输到 S/S,但有一个问题。我希望代码继续浏览 pdf 页面并在最后停止。问题在于如何让进程识别pdf中显示的页面:
Sub Trial()
Dim adobeReaderPath As String
Dim pathAndFileName As String
Dim shellPathName As String
Dim lastrow4 As Long
Dim ws As Worksheet
Dim displaypage As Integer
pathAndFileName = "C:\New Folder\2002.pdf"
adobeReaderPath = "C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe"
shellPathName = adobeReaderPath & " """ & pathAndFileName & """"
Call Shell( _
pathname:=shellPathName, _
windowstyle:=vbNormalFocus)
Application.Wait Now + TimeValue("00:00:2")
SendKeys "^a"
SendKeys "^c"
ThisWorkbook.Activate
Set ws = ThisWorkbook.Sheets(1)
Range("A1").Select
ws.Paste
Application.CutCopyMode = False
Application.Wait Now + TimeValue("00:00:1")
SendKeys "^{PGDN}"
'the problem starts here there is no recognition of the display page number and it moves to the else part
If displaypage = 2 Then
SendKeys "^a"
SendKeys "^c"
Application.Wait Now + TimeValue("00:00:1")
ThisWorkbook.Activate
lastrow4 = Sheets("Sheet1").Range("A65536").End(xlUp).Row
Range("A" & lastrow4 + 1).Select
ws.Paste
Else
SendKeys "^q"
End If
如果我省略“显示页面”if/then 序列并使用一定数量的 pdf 页面,它工作正常,但我希望它是开放式的,因此我可以将其格式化为任何大小的文档,并在它完成时停止所有页面。我不需要 do until 或 loop 部分,我只需要知道如何设置东西来识别 pdf 在哪个页面上,这样它就会正确地通过 If 序列。 谢谢, 外星人
【问题讨论】:
-
我能够调整此代码以供使用。也许其他人也可以使用它。