使用adobe reader将pdf文件转换为excel
我有一台没有互联网的电脑,需要能够将pdf文件转换为excel,我只有adobe reader,获得adobe professional是不可能的 目前我有这段代码,它非常适合使用excel(或任何其他office应用程序)打开pdf文件: 如何使用vba将文件内容复制到工作表中?使用adobe reader将pdf文件转换为excel,excel,pdf,file-conversion,Excel,Pdf,File Conversion,我有一台没有互联网的电脑,需要能够将pdf文件转换为excel,我只有adobe reader,获得adobe professional是不可能的 目前我有这段代码,它非常适合使用excel(或任何其他office应用程序)打开pdf文件: 如何使用vba将文件内容复制到工作表中? 这几乎是我所需要的全部,但如果能将pdf文件中的内容安排到不同的栏目,我将不胜感激 我花了一些时间想出来,尽了我最大的努力,如果有人有更好、更可靠的代码,不依赖于关键事件,请分享 Option Explicit Di
这几乎是我所需要的全部,但如果能将pdf文件中的内容安排到不同的栏目,我将不胜感激 我花了一些时间想出来,尽了我最大的努力,如果有人有更好、更可靠的代码,不依赖于关键事件,请分享
Option Explicit
Dim ShortFileName As String
Dim myRange As Range
Dim NumRows
Dim strg As String
Dim wb As Workbook
Dim intChoice As Integer
Dim Full_File_Path As String
Dim i As Long
Dim NumberOfPages As Long
Dim Current_Page As Long
Dim Current_Cell As Integer
Dim StartingRow As Integer
Dim WrdArray() As String
Dim text_string As String
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function PostMessage _
Lib "user32" Alias "PostMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Function OpenPDFPage(PDFPath As String, PageNumber As Long, PageView As Integer)
'Opens a pdf file, at specific page and with specific view.
'Sendkeys method is used for simulating keyboard shortcuts.
'It can be used with both Adobe Reader & Adobe Professional.
'By Christos Samaras
'This line depends on the apllication you are using.
'For Word
'ThisDocument.FollowHyperlink PDFPath, NewWindow:=True
'For Power Point
'ActivePresentation.FollowHyperlink PDFPath, NewWindow:=True
'For Excel
ThisWorkbook.FollowHyperlink PDFPath, NewWindow:=True
SendKeys ("^+N" & PageNumber & "~^" & PageView), True
End Function
Sub Test()
Application.ScreenUpdating = False
Set wb = ActiveWorkbook
Set myRange = Range("B:B") ' change the address to whatever suits you
Application.FileDialog(msoFileDialogOpen).InitialFileName = Range("A1").Value
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
intChoice = Application.FileDialog(msoFileDialogOpen).Show
'Select the start folder
'make the file dialog visible to the user
'determine what choice the user made
If intChoice <> 0 Then
'get the file path selected by the user
Full_File_Path = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
Range("A1").Value = Full_File_Path ' change the address to whatever suits you
NumberOfPages = GetPageNum(Full_File_Path)
ShortFileName = Dir(Full_File_Path)
For Current_Page = 1 To NumberOfPages
OpenPDFPage Full_File_Path, Current_Page, 1
'Page view options:
'0: Full Page
'1: Zoom to 100%
'2: Page Width
StartingRow = 1 + Application.WorksheetFunction.CountA(myRange)
For i = 1 To 11
Debug.Print Now()
Sleep 7
SendKeys "^a", True
SendKeys "^c", True
Next i
wb.ActiveSheet.Cells(StartingRow, 3).Value = Current_Page
For i = 1 To 11
Debug.Print Now()
Sleep 7
wb.ActiveSheet.Cells(StartingRow, 2).Select
On Error Resume Next
Selection.PasteSpecial
Next i
NumRows = 1 + Application.WorksheetFunction.CountA(myRange)
wb.ActiveSheet.Cells(NumRows, 2).Value = "."
If Current_Page = NumberOfPages Then
Call PostMessage(FindWindow(vbNullString, ShortFileName & " - Adobe Acrobat Reader DC"), 16, 0, 0)
End If
For Current_Cell = StartingRow To NumRows
text_string = Cells(Current_Cell, 2)
WrdArray() = Split(text_string)
For i = LBound(WrdArray) To UBound(WrdArray)
strg = strg & vbNewLine & "Part No. " & i & " - " & WrdArray(i)
Cells(Current_Cell, 50 - i) = WrdArray(i)
strg = 0
text_string = 0
Next i
Next Current_Cell
Next Current_Page
End If
Application.ScreenUpdating = True
Exit Sub
End Sub
Function GetPageNum(PDF_File As String)
'Haluk 19/10/2008
Dim FileNum As Long
Dim strRetVal As String
Dim RegExp
Set RegExp = CreateObject("VBscript.RegExp")
RegExp.Global = True
RegExp.Pattern = "/Type\s*/Page[^s]"
FileNum = FreeFile
Open PDF_File For Binary As #FileNum
strRetVal = Space(LOF(FileNum))
Get #FileNum, , strRetVal
Close #FileNum
GetPageNum = RegExp.Execute(strRetVal).Count
End Function
选项显式
将短文件名设置为字符串
将myRange变暗为Range
朦胧的NumRows
作为字符串的Dim strg
将wb设置为工作簿
选择整数
将完整文件路径变暗为字符串
我想我会坚持多久
变暗的页数等于长的页数
将当前页面变暗为长
将当前单元格设置为整数
Dim StartingRow为整数
Dim WrdArray()作为字符串
Dim text_字符串作为字符串
#如果是VBA7,则
公共声明PtrSafe子睡眠库“kernel32”(ByVal dwr作为LongPtr)
#否则
公共声明子睡眠库“kernel32”(ByVal的长度为毫秒)
#如果结束
声明函数FindWindow_
Lib“user32”别名“FindWindowA”(_
ByVal lpClassName作为字符串_
ByVal lpWindowName(作为字符串)长度相同
声明函数PostMessage_
Lib“user32”别名“PostMessageA”(_
再见,只要_
ByVal wMsg,只要_
拜瓦尔·瓦帕兰,只要_
ByVal lParam As Long)As Long
函数OpenPDFPage(PDFPath为字符串,PageNumber为长,PageView为整数)
'在特定页面和特定视图打开pdf文件。
'Sendkeys方法用于模拟键盘快捷键。
“它可以与Adobe Reader和Adobe Professional一起使用。
”“克里斯托斯·萨马拉斯
'此行取决于您使用的应用程序。
”他说
'ThisDocument.FollowHyperlink PDFPath,NewWindow:=True
'电源点
'ActivePresentation.FollowHyperlink PDFPath,NewWindow:=True
“为了Excel
ThisWorkbook.FollowHyperlink PDFPath,NewWindow:=True
SendKeys(“^+N”&PageNumber&“~^”&PageView),True
端函数
子测试()
Application.ScreenUpdating=False
设置wb=ActiveWorkbook
设置myRange=Range(“B:B”)'将地址更改为适合您的地址
Application.FileDialog(msoFileDialogOpen).InitialFileName=Range(“A1”).Value
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect=False
intChoice=Application.FileDialog(msoFileDialogOpen.Show)
'选择开始文件夹
'使文件对话框对用户可见
'确定用户所做的选择
如果选择0,那么
'获取用户选择的文件路径
完整文件路径=Application.FileDialog(msoFileDialogOpen)。选择editems(1)
Range(“A1”).Value=Full\u File\u Path'将地址更改为适合您的地址
NumberOfPages=GetPageNum(完整文件路径)
ShortFileName=Dir(完整文件路径)
对于当前页面=1到页数
OpenPDFPage完整文件路径,当前页面,1
'页面视图选项:
“0:整页
'1:缩放到100%
'2:页面宽度
StartingRow=1+Application.WorksheetFunction.CountA(myRange)
对于i=1到11
Debug.Print Now()
睡眠7
SendKeys“^a”,对吗
SendKeys“^c”,对吗
接下来我
wb.ActiveSheet.Cells(StartingRow,3).Value=当前页面
对于i=1到11
Debug.Print Now()
睡眠7
wb.ActiveSheet.Cells(开始行,2)。选择
出错时继续下一步
选择特别的
接下来我
NumRows=1+应用程序.WorksheetFunction.CountA(myRange)
wb.ActiveSheet.Cells(NumRows,2).Value=“”
如果当前页面=页数,则
调用PostMessage(FindWindow(vbNullString,ShortFileName&“-adobeacrobatreaderdc”),16,0,0
如果结束
对于当前_单元格=开始行到NumRows
文本\字符串=单元格(当前\单元格,2)
WrdArray()=拆分(文本字符串)
对于i=LBound(WrdArray)到UBound(WrdArray)
strg=strg&vbNewLine&“零件号”&i&“-”&WrdArray(i)
单元(当前_单元,50-i)=WrdArray(i)
strg=0
文本字符串=0
接下来我
下一个当前单元
下一个当前页面
如果结束
Application.ScreenUpdating=True
出口接头
端接头
函数GetPageNum(PDF_文件为字符串)
“Haluk 19/10/2008
Dim FileNum尽可能长
作为字符串的Dim strertval
Dim RegExp
设置RegExp=CreateObject(“VBscript.RegExp”)
RegExp.Global=True
RegExp.Pattern=“/Type\s*/Page[^s]”
FileNum=FreeFile
以#FileNum的形式打开二进制文件的PDF_文件
stretval=空间(LOF(FileNum))
获取#FileNum,stretval
关闭#FileNum
GetPageNum=RegExp.Execute(stretval.Count)
端函数
Option Explicit
Dim ShortFileName As String
Dim myRange As Range
Dim NumRows
Dim strg As String
Dim wb As Workbook
Dim intChoice As Integer
Dim Full_File_Path As String
Dim i As Long
Dim NumberOfPages As Long
Dim Current_Page As Long
Dim Current_Cell As Integer
Dim StartingRow As Integer
Dim WrdArray() As String
Dim text_string As String
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function PostMessage _
Lib "user32" Alias "PostMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Function OpenPDFPage(PDFPath As String, PageNumber As Long, PageView As Integer)
'Opens a pdf file, at specific page and with specific view.
'Sendkeys method is used for simulating keyboard shortcuts.
'It can be used with both Adobe Reader & Adobe Professional.
'By Christos Samaras
'This line depends on the apllication you are using.
'For Word
'ThisDocument.FollowHyperlink PDFPath, NewWindow:=True
'For Power Point
'ActivePresentation.FollowHyperlink PDFPath, NewWindow:=True
'For Excel
ThisWorkbook.FollowHyperlink PDFPath, NewWindow:=True
SendKeys ("^+N" & PageNumber & "~^" & PageView), True
End Function
Sub Test()
Application.ScreenUpdating = False
Set wb = ActiveWorkbook
Set myRange = Range("B:B") ' change the address to whatever suits you
Application.FileDialog(msoFileDialogOpen).InitialFileName = Range("A1").Value
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
intChoice = Application.FileDialog(msoFileDialogOpen).Show
'Select the start folder
'make the file dialog visible to the user
'determine what choice the user made
If intChoice <> 0 Then
'get the file path selected by the user
Full_File_Path = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
Range("A1").Value = Full_File_Path ' change the address to whatever suits you
NumberOfPages = GetPageNum(Full_File_Path)
ShortFileName = Dir(Full_File_Path)
For Current_Page = 1 To NumberOfPages
OpenPDFPage Full_File_Path, Current_Page, 1
'Page view options:
'0: Full Page
'1: Zoom to 100%
'2: Page Width
StartingRow = 1 + Application.WorksheetFunction.CountA(myRange)
For i = 1 To 11
Debug.Print Now()
Sleep 7
SendKeys "^a", True
SendKeys "^c", True
Next i
wb.ActiveSheet.Cells(StartingRow, 3).Value = Current_Page
For i = 1 To 11
Debug.Print Now()
Sleep 7
wb.ActiveSheet.Cells(StartingRow, 2).Select
On Error Resume Next
Selection.PasteSpecial
Next i
NumRows = 1 + Application.WorksheetFunction.CountA(myRange)
wb.ActiveSheet.Cells(NumRows, 2).Value = "."
If Current_Page = NumberOfPages Then
Call PostMessage(FindWindow(vbNullString, ShortFileName & " - Adobe Acrobat Reader DC"), 16, 0, 0)
End If
For Current_Cell = StartingRow To NumRows
text_string = Cells(Current_Cell, 2)
WrdArray() = Split(text_string)
For i = LBound(WrdArray) To UBound(WrdArray)
strg = strg & vbNewLine & "Part No. " & i & " - " & WrdArray(i)
Cells(Current_Cell, 50 - i) = WrdArray(i)
strg = 0
text_string = 0
Next i
Next Current_Cell
Next Current_Page
End If
Application.ScreenUpdating = True
Exit Sub
End Sub
Function GetPageNum(PDF_File As String)
'Haluk 19/10/2008
Dim FileNum As Long
Dim strRetVal As String
Dim RegExp
Set RegExp = CreateObject("VBscript.RegExp")
RegExp.Global = True
RegExp.Pattern = "/Type\s*/Page[^s]"
FileNum = FreeFile
Open PDF_File For Binary As #FileNum
strRetVal = Space(LOF(FileNum))
Get #FileNum, , strRetVal
Close #FileNum
GetPageNum = RegExp.Execute(strRetVal).Count
End Function