|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
今天遇到了同样的问题,要根据PDF的内容对文件重命名
上网查了资料,可能是因为公司没装完整的软件,用不了
后来想了一个办法
用PDF阅读器打开文件
模拟键盘快捷键将文件另存为txt到桌面
手动把生成的TXT文件放到新文件夹
提取TXT文件指定行的文本
因为是模拟键盘按键操作,有时会漏掉几个文件
- Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
- Sub A_PDF转TXT()
- Dim fsys As New FileSystemObject
- Dim Data_path As String
- Dim n As Integer
- t = Timer
- Data_path = ThisWorkbook.Path & "\数据源"
- n = 1
- Sheets("列表").Cells.Clear
- Sheets("列表").[A1:C1].Value = Array("PDF", "TXT", "公司")
- Set xfolder = fsys.GetFolder(Data_path)
- For Each xfile In xfolder.Files
- If xfile.Name Like "*.pdf" Then
- n = n + 1
- Sheets("列表").Cells(n, 1).Value = xfile.Name
- Sheets("列表").Cells(n, 2).Value = Replace(xfile.Name, "pdf", "txt")
-
- Shell "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe " & xfile.Path
- Shell "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe " & xfile.Path
-
- Sleep 500
- Application.SendKeys "%F"
- Sleep 500
- Application.SendKeys "V"
- Sleep 500
- Application.SendKeys "~"
- Sleep 500
- Application.SendKeys "%{F4}"
-
- End If
- Next xfile
- MsgBox ("运行结束,请将桌面的TXT文件放入TXT文件夹中。")
- End Sub
- Sub B_提取TXT公司并改名()
- Dim fsys As New FileSystemObject
- Dim Data_path1 As String
- Dim Data_path2 As String
- Dim n As Integer
- Data_path1 = ThisWorkbook.Path & "\TXT"
- Data_path2 = ThisWorkbook.Path & "\数据源"
- n = 2
- Do While Sheets("列表").Cells(n, 2).Value <> ""
- On Error Resume Next
- Set A = fsys.OpenTextFile(Data_path1 & Sheets("列表").Cells(n, 2).Value, 1)
- For i = 1 To 33
- A.ReadLine
- Next i
- Sheets("列表").Cells(n, 3).Value = A.ReadLine
- Name Data_path2 & Sheets("列表").Cells(n, 1).Value As Data_path2 & Sheets("列表").Cells(n, 3).Value & ".pdf"
- n = n + 1
- Loop
- End Sub
复制代码
根据PDF内容批量修改PDF文件名.zip
(19.74 KB, 下载次数: 473)
|
评分
-
1
查看全部评分
-
|