Macrocomanda se poate folosi pentru a converti toate documentele (în format .doc și .docx) dintr-un folder în fișiere de tip .pdf, în același folder.
Macrocomanda cere calea la folderul cu documente, apoi deschide fiecare fișier, îl salvează în format .pdf, închide documentul și trece la următorul.
După ce a terminat de salvat toate documentele, afișează mesajul: „Conversia s-a terminat!”
Sub ConvertWordToPDF()
'se selecteaza folderul cu fisiere doc sau docx,
'apoi macrocomanda deschide fiecare fisier doc sau docx
'si il salveaza ca pdf
Dim folderPath As String
Dim fileName As String
Dim doc As Document
' Select folder
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Selecteaza folderul cu fisiere Word"
If .Show <> -1 Then Exit Sub
folderPath = .SelectedItems(1) & "\"
End With
' Loop prin fisiere .docx
fileName = Dir(folderPath & "*.doc*")
While fileName <> ""
If LCase(Right(fileName, 4)) = ".doc" Or _
LCase(Right(fileName, 5)) = ".docx" Then
Set doc = Documents.Open(folderPath & fileName)
doc.ExportAsFixedFormat _
OutputFileName:=folderPath & Left(fileName, InStrRev(fileName, ".") - 1) & ".pdf", _
ExportFormat:=wdExportFormatPDF
doc.Close SaveChanges:=False
End If
fileName = Dir
Wend
MsgBox "Conversia s-a terminat!"
End Sub