|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub ReadFromPDF()
Application.DisplayAlerts = False
Dim wApp As New Word.Application
Dim wDoc As Word.Document
Dim pg As Word.paragraph
Dim wLine As String
Dim tbCount As Integer
Dim tbindx As Integer
Dim lr As Long
Dim tRow As Long, tCol As Long
Dim fopen As FileDialog
Set fopen = Application.FileDialog(msoFileDialogFilePicker)
wApp.Visible = False
Call SelectFile(WJM)
'''fopen.InitialFileName = "*.pdf"
'''fopen.Show
WJM = fopen.SelectedItems(1)
Set wDoc = wApp.Documents.Open(WJM, False) ''''Open(ThisWorkbook.Path & "\" & WJM & ".pdf", False)
tbCount = wDoc.Tables.Count
If wDoc.Tables.Count > 0 Then
For tbindx = 1 To tbCount
With wDoc.Tables(tbindx)
lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row + 1
Cells(lr, 1).Value = "table-" & tbindx
For tRow = 1 To .Rows.Count
lr = Sheet1.Range("a" & Rows.Count).End(xlUp).Row
For tCol = 1 To .Columns.Count
On Error Resume Next
Cells(lr + 1, tCol).Value = Format(WorksheetFunction.Trim(WorksheetFunction.Clean(.Cell(tRow, tCol).Range.Text)), "@")
On Error GoTo 0
Next tCol
Next tRow
End With
Next tbindx
End If
wDoc.Close False
Set wApp = Nothing
wApp.Quit
Set wApp = Nothing
Application.DisplayAlerts = False
End Sub
只能应表格这种很规范的数据,像发票就不行了。
发票的格式没有统一,不同省市的发票看打印结果是一样的,但后台的格式却五花八门,有的还用了文本框,有的没用。
PDF发票要整理出来就比较有挑战性。
|
评分
-
1
查看全部评分
-
|