RunTime Error 462 while converting word docx to PDF

SydneyBuoy

New Member
Joined
Sep 9, 2019
Messages
4
'******* EmpFolder is a Global Variable containing Folder Path *************************

Sub BatchConvertDocxToPDF()
Dim objDoc1 As Document
Dim strFile As String, strFolder As String

'Initialization
strFolder = EmpFolder & ""
strFile = Dir(strFolder & "*.docx", vbNormal)

'Precess each file in the file folder and convert them to pdf.
While strFile <> ""
Set objDoc1 = Documents.Open(Filename:=strFolder & strFile)

objDoc1.ExportAsFixedFormat _
OutputFileName:=Replace(objDoc1.FullName, ".docx", ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, Item:=wdExportDocumentContent

objDoc1.Close
strFile = Dir()
Wend
End Sub


The following line is highlighted as the error "Set objDoc1 = Documents.Open(Filename:=strFolder & strFile)". Run Time Error 462: The Remote Server Machine does not exist or is unavailable.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

I am trying to change several word files to pdf, the first file works, but when I run the second file I get the error:​

RunTime Error 462 while converting word docx to PDF​


When the program stops I will see the Debug option, it shows the following instruction

DOCUMENTS.Open FileName:=FileDocPath, _
ConfirmConversions:=False, _
ReadOnly:=False, _
AddToRecentFiles:=False, _
PasswordDocument:="", _
PasswordTemplate:="", _
Revert:=False, _
WritePasswordDocument:="", _
WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto, _
XMLTransform:=""
 
Upvote 0
Is this code in Word? Does FileDocPath contain the correct document name (hopefully not the name of the document with the code in)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top