使用 VBA 批量转换 Office 文档格式

Sub FormatConverter()
Set instance = Documents ' 实例对象: Word=Documents | Excel=Workbooks | PowerPoint=Presentations
Const fromExt = "doc" ' 原始格式扩展名
Const toId = 12 ' 目标格式ID: doc=0 | docx=12 | xls=56 | xlsx=51 | ppt=1 | pptx=24
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
dialog.Filters.Add fromExt, "*." + fromExt, 1
dialog.Show
For Each item In dialog.SelectedItems
Set file = instance.Open(FileName:=item, ReadOnly:=True, Visible:=False)
file.SaveAs Left(item, InStrRev(item, ".") - 1), toId
file.Close
Next
End Sub

Change Log

20210226

20180823

20180626