如何批量将word文档转换为PDF

新建一个txt文件将以下代码复制进去
 

On Error Resume Next
Set wordTest = CreateObject("Word.Application")
If Err.Number <> 0 Then
    MsgBox "Microsoft Word not found! Please install Word first.", vbCritical, "Error"
    WScript.Quit
End If
wordTest.Quit
Set wordTest = Nothing
On Error GoTo 0
On Error Resume Next

Set fso = CreateObject("Scripting.FileSystemObject")
currentFolder = fso.GetAbsolutePathName(".")
pdfFolder = currentFolder & "\PDF"

If Not fso.FolderExists(pdfFolder) Then
    fso.CreateFolder pdfFolder
End If

Set wordApp = CreateObject("Word.Application")
wordApp.Visible = False
wordApp.DisplayAlerts = False

Set folder = fso.GetFolder(currentFolder)
For Each file In folder.Files
    ext = LCase(fso.GetExtensionName(file.Name))
    
    If ext = "doc" Or ext = "docx" Then
        fullPath = file.Path
        pdfPath = pdfFolder & "\" & fso.GetBaseName(file.Name) & ".pdf"
        
        If Not fso.FileExists(pdfPath) Then
            On Error GoTo 0
            Set doc = wordApp.Documents.Open(fullPath)
            doc.SaveAs pdfPath, 17
            doc.Close False
            On Error Resume Next
        End If
    End If
Next

wordApp.Quit False
Set doc = Nothing
Set wordApp = Nothing
Set fso = Nothing


MsgBox "转换完成PDF存储在 : " & pdfFolder, vbInformation

选择另存为修改编码为ANSI避免乱码
如何批量将word文档转换为PDF_第1张图片
修改扩展名为vbs,将文件和你想转换的word文档放到同一文件夹,双击后等待,
转换完成后会弹出提示框,注意文件越多等待时间越长。不要多次点击
如何批量将word文档转换为PDF_第2张图片

你可能感兴趣的:(word,pdf,c#)