I am trying to run below macro but get a "Run-time error 462 : The remote server machine does not exist or is unavailable” with line 12 highlighted on the debug of below code.
I have searched all over for a resolution, any help and support would be much appreciated.
Code
Sub Word_To_PDF()
Dim objDoc As Document
Dim strFile As String, strFolder As String
'Initialization
strFolder = "D:\My Documents\VBA\Test folder\"
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
Kill "D:\My Documents\VBA\Test folder\*.doc*"
End Sub
Display More