hi guys,
i have a word macro and i want to make it to work the same from excel.
Can anyone help me to customize it to work in Excel?
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
Dim Path As String, FileFormat As String, filename As String
Application.DisplayAlerts = False
On Error Resume Next
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 directory & "\" & newName, FileFormat:=17
wdDoc.Close SaveChanges:=False
Next file
On Error GoTo 0
Application.DisplayAlerts = True
End Sub
Bookmarks