Hi guys,
I have a macro code that export all the words files from a folder into pdf.
I shared the code with other peers and it seems that for them it doesn't work. If they have 10 words only 3 of them are exported as pdf and 1 from those 3 has an odd name.
***All of those 10 files are .docx files.
If is possible, can you please advise what I've done wrong?
Also is there a possibility to change the destination folder of the saved files? Currently the code exports all the pdfs into C/Documents. This can be changed?
Ps. For me this code is working perfectly.
Thank you in advance,
Ionut
Sub ConvertWordsToPdfs() Dim directory As Variant Dim file As Object Dim files As Object Dim folder As Variant Dim n As Long Dim newName As String Dim wdDoc As Document With Application.FileDialog(msoFileDialogFolderPicker) .Show If .SelectedItems.Count = 0 Then Exit Sub directory = .SelectedItems(1) End With With CreateObject("Shell.Application") Set folder = .Namespace(directory) Set files = folder.Items files.Filter 64, "*.docx" End With For Each file In files n = InStrRev(file.Name, ".") newName = Left(file.Name, n) & "pdf" Set wdDoc = Documents.Open(file.Path) wdDoc.SaveAs2 FileName:=newName, FileFormat:=wdFormatPDF wdDoc.Close SaveChanges:=False Next file End Sub
Bookmarks