【发布时间】:2020-09-19 12:37:44
【问题描述】:
我有很多 PDF 文件要转换为 Excel。我找到了下面的代码,它通过在 word 中打开 pdf 文件将 PDF 转换为 excel,但它在 Dim fso As New FileSystemObject 失败,因为 mac excel 没有脚本字典。如何修改代码以在 word 中打开 PDF 文件而无需使用脚本字典?
Option Explicit
Sub pdf_to_excel()
Dim setting_sh As Worksheet
Set setting_sh = ThisWorkbook.Sheets("Setting")
Dim pdf_path As String
Dim excel_path As String
pdf_path = setting_sh.Range("E11").Value
excel_path = setting_sh.Range("E12").Value
Dim fso As New FileSystemObject
Dim fo As Folder
Dim f As File
Set fo = fso.Getfolder(pdf_path)
Dim wa As Object
Dim doc As Object
Dim wr As Object
Set wa = CreateObject("word.application")
wa.Visible = True
Dim nwb As Workbook
Dim nsh As Worksheet
For Each f In fo.Files
Set doc = wa.documents.Open(f.Path, False, Format:="PDF files")
Set wr = doc.Paragraphs(1).Range
wr.WholeStory
Set nwb = Workbooks.Add
Set nsh = nwb.Sheets(1)
wr.Copy
nsh.Paste
nwb.SaveAs (excel_path & "\" & Replace(f.Name, ".pdf", ".xlsx"))
doc.Close False
nwb.Close False
Next
wa.Quit
MsgBox "Done"
End Sub
【问题讨论】:
-
如果您有兴趣,可以使用非编程选项来执行此操作。
-
@jmh 我有兴趣。
标签: excel vba macos pdf ms-word