Hi Guys, Part of my job involves combining dozens of word docs and pdf's into a single PDF. As PDF files combines waaay faster within Adobe pro than word docs I am using a macro to convert all word docs within a folder to pdf (it does this quickly) I then go in afterwards and have to manually delete the word docs... you can see where im going with this.
I'm very new to this and have Frankenstein'ed code from various places in order to have it delete the word docs after the conversion and would love some advice.
TL:DR, Requesting your beautiful assistance in deleting only .doc files within a folder using a string from the previous sub as the directory location. My efforts so far pasted below
Sub Run()
Call ExportWordToPDF
Call KillDocs
End Sub
Public Sub ExportWordToPDF()
Dim strFilename As String
Dim strDocName As String
Dim strpath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Dim intPos As Integer
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled", , "List Folder Contents"
Exit Sub
End If
strpath = fDialog.SelectedItems.Item(1)
If Right(strpath, 1) <> "\" Then strpath = strpath + "\"
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strpath, 1) = Chr(34) Then
strpath = Mid(strpath, 2, Len(strpath) - 2)
End If
strFilename = Dir$(strpath & "*.doc")
While Len(strFilename) <> 0
Set oDoc = Documents.Open(strpath & strFilename)
strDocName = ActiveDocument.FullName
intPos = InStrRev(strDocName, ".")
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & ".pdf"
oDoc.SaveAs2 FileName:=strDocName, _
FileFormat:=wdExportFormatPDF, _
CompatibilityMode:=14
strFilename = Dir$()
oDoc.Close SaveChanges:=wdDoNotSaveChanges
Wend
End Sub
Sub KillDocs()
Kill strpath & "\" & "*" & .doc
MsgBox "Completed"
End Sub
Bookmarks