|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
提取pdf文件名和页码
- Sub pdfcount()
- Dim FileName As String
- Dim Match, Str$, P%
- ActiveSheet.UsedRange.Clear
- FileToOpen = Application.GetOpenFilename("PDF文件(*.PDF),*.PDF", , "Please select the files...", , True)
- If IsArray(FileToOpen) = 0 Then
- 'MsgBox "没有选择文件"
- MsgBox "No files are selected!"
- WS1.Unprotect
- GoTo ErrorHandler
- End If
- For i = 1 To UBound(FileToOpen)
- userfilename = FileToOpen(i)
- With CreateObject("scripting.filesystemobject").opentextfile(FileToOpen(i))
- Str = .readall
- .Close
- End With
- P = 0
- With CreateObject("vbscript.regexp")
- .Global = True
- .MultiLine = True
- .Pattern = "\/Count ([\d]+)"
- If .test(Str) Then
- For Each Match In .Execute(Str)
- If Val(Match.submatches(0)) > P Then P = Val(Match.submatches(0))
- Next Match
- End If
- End With
- Cells(1, 1) = "文件名"
- Cells(1, 2) = "页码"
- 'Cells(i + 1, 1) = userfilename
- Cells(i + 1, 1) = Split(userfilename, "")(UBound(Split(userfilename, "")))
- Cells(i + 1, 2).Value = P
- Next i
- ErrorHandler:
- MsgBox ("统计页码完成")
- End Sub
复制代码 |
|