咔片PPT · AI自动生成演示文稿,模板丰富、排版精美 讯飞智文 · 一键生成PPT和Word,高效应对学习与办公

平常工作中涉及到需要将PDF转成WORD格式方便后续的数据处理。使用VBA可以很容易实现。
实现的过程如下:
1.设计一个文件包,如下所示意。


2.使用WORD作为实现的操作界面,这个可以根据实际的需要进行设计。


3.实现的代码如下:


4.实现后的效果:



源码如下:

Sub PdftoWord()

Dim file As Variant, i As Integer

file = Dir("E:Y2020AutomationPhysical Lab DDE" & "*.pdf")

i = 1

Do While (file <> "")

ChangeFileOpenDirectory ("E:Y2020AutomationPhysical Lab DDE")

Documents.Open FileName:=file, ConfirmConversions:=False, ReadOnly:=False, Format:=wdOpenFormatAuto

ChangeFileOpenDirectory "E:Y2020AutomationPhysical Lab DDEWord"

ActiveDocument.SaveAs2 (Replace(file, "pdf", ".docx"))

ActiveDocument.Close

ThisDocument.Tables(1).Cell(1, 1).Range = "序号"

ThisDocument.Tables(1).Cell(1, 2).Range = "文件名"

ThisDocument.Tables(1).Cell(1, 3).Range = "时间"

i = i + 1

Debug.Print i

ThisDocument.Tables(1).Cell(i, 1).Range = i - 1

ThisDocument.Tables(1).Cell(i, 2).Range = file

ThisDocument.Tables(1).Cell(i, 3).Range = Now()

file = Dir

Loop

End Sub