I am very new too VBA and I am trying to automate converting word documents to pdf files. I have figured out how to convert all word documents within a single folder to pdf. Now I am struggling to apply that methodology to word documents across all subfolders in a directory. Is there a way to incorporate that in the code below? To add to it, can we pick specific word documents in these folders and convert them to pdf?
Sub BatchConvertDocxToPDF()
Dim objDoc As Document
Dim strFile As String, strFolder As String
'Initialization
strFolder = "C:\Users\Test\Desktop\Test Files\"
strFile = Dir(strFolder & "*.docx", vbNormal)
'Precess each file in the file folder and convert them to pdf.
While strFile <> ""
Set objDoc = Documents.Open(FileName:=strFolder & strFile)
objDoc.ExportAsFixedFormat _
OutputFileName:=Replace(objDoc.FullName, ".docx", ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, Item:=wdExportDocumentContent
objDoc.Close
strFile = Dir()
Wend
End Sub