I am automating processing of PDF files via VBA, but the problem I cannot seem to resolve is Word helpfully showing a dialog box regarding file conversion. I am looking for a solution which doesn't require modifying the Registry, as this is not permitted in the work environment
Word will now convert your PDF to an editable Word Document...
This dialog does offer a check-box 'Don't show this message again' which works as advertised, but I need the code to be portable across PCs and users
The host application is actually Access, where I have a reference to the Microsoft Word 16.0 Object Library. I also tried directly in Word with the same issue.
Below is the code I'm using - it does work, other than that Word provides a dialog box which I don't want.
Sub convertPDFtoTextViaWord()
Const filePath As String = "C:\myfilepath\"
Dim file As String, fileName As String
Dim myWord As Word.Application, myDoc As Word.Document
Set myWord = New Word.Application
file = Dir(filePath & "*.pdf")
myWord.DisplayAlerts = wdAlertsNone
Do While file <> ""
fileName = Replace(file, "pdf", "txt")
Set myDoc = myWord.Documents.Open(fileName:=filePath & file, ConfirmConversions:=False, Format:="PDF Files")
myDoc.SaveAs2 filePath & fileName, FileFormat:=wdFormatText, Encoding:=1252, lineending:=wdCRLF
myDoc.Close False
file = Dir
Loop
Set myDoc = Nothing
Set myWord = Nothing
End Sub
I should note that this code does as intended now that I have selected the 'Don't show this message again' checkbox, but I want to programmatically avoid the need to do this, as I will not always be in a position to perform this manual step
I should also note that I tried running the same code (with a few appropriate modifications) directly in Word with the same result
I added the line myWord.DisplayAlerts = wdAlertsNone
because this is how I would do it in Excel (where I have far more VBA experience)
I also tried changing Format:="PDF Files"
to Format:=wdOpenFormatAuto
(which is the default value for the parameter, anyway) with no change
To reiterate, the code works as desired other than that I can't suppress the dialog box which it seems should be exactly what ConfirmConversions:=False
supports.
Using Office365 ProPlus
Thanks