Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
This Excel macro below should convert all .Docx into the selected folder to .Pdf
Here is the code line which provide me the error Code 429, But several hours ago this same line of code was working.
Documents.Open (filePath & currFile) 'Error Code 429
Here the full macro's code
Sub ConvertDocxInDirToPDF()
Dim filePath As String
Dim currFile As String
filePath = ActiveWorkbook.Path & "\"
MsgBox filePath
currFile = Dir(filePath & "*.docx")
Do While currFile <> ""
Documents.Open (filePath & currFile) 'Error Code 429
Documents(currFile).ExportAsFixedFormat _
OutputFileName:=filePath & Left(currFile, Len(currFile) - Len(".docx")) & ".pdf", _
ExportFormat:=17
Documents(currFile).Close
currFile = Dir()
Application.ScreenUpdating = True
End Sub
Is there a simple way to make this macro working and to fix this error.
Best regards.
–
What does this mean? If the Microsoft Word 1X.0
reference is checked (VBE>Extras>Libraries), then the code below works quite ok:
Sub TestMe()
Dim filePath As String
filePath = ThisWorkbook.Path & "\"
Dim currFile As String
currFile = Dir(filePath & "*.docx")
Dim wrdDoc As Object
Documents.Open filePath & currFile
End Sub
If the "MS Word Object Library" is not referred, then with late binding it still could be referred to the object. (Late binding is CreateObject("Word.Application")
):
Sub TestMe()
Dim filePath As String
filePath = ThisWorkbook.Path & "\"
Dim currFile As String
currFile = Dir(filePath & "*.docx")
Dim wrdApps As Object
Set wrdApps = CreateObject("Word.Application")
wrdApps.Documents.Open (filePath & currFile)
End Sub
If needed, Documents.Open
may return a document object:
Sub TestMe()
Dim filePath As String
filePath = ThisWorkbook.Path & "\"
Dim currFile As String
currFile = Dir(filePath & "*.docx")
Dim wrdApps As Object
Set wrdApps = CreateObject("Word.Application")
Dim wrdDoc As Object
Set wrdDoc = wrdApps.Documents.Open(filePath & currFile)
End Sub
Documentation
–
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.