Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-18-2017, 03:52 AM
ballpoint ballpoint is offline Looping through a folder of PDF files and saving them as docx Windows 10 Looping through a folder of PDF files and saving them as docx Office 2016
Advanced Beginner
Looping through a folder of PDF files and saving them as docx
 
Join Date: Sep 2017
Posts: 40
ballpoint is on a distinguished road
Default Looping through a folder of PDF files and saving them as docx

I have recently realised that a large number of PDFs can be opened within Word on Windows retaining the formatting and the footnotes. Accordingly, I thought I'd try it on a collection of files I have. Problem is, I cannot seem to loop through the PDF files in a folder and saving them as .docx.

I have managed to get it to open the files, but not to save them as .docx. Ideally, I would also need some insight as to how to bypass error messages and proceed to the next file when that happens, but I have not been able to find a way to do that either.



I must have made some major mistakes on the way, but below is what I have tried. Many thanks!



Code:
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.pdf", vbNormal)
While strFile <> ""
  Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
 ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatPDF
 ActiveWindow.Close SaveChanges = False
    .Close SaveChanges:=True
  End With
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping through a folder of PDF files and saving them as docx Run Code on all files and save files as .docx Plokimu77 Word VBA 4 06-05-2016 04:41 PM
Looping through a folder of PDF files and saving them as docx Macro to change all text color to black in all docx files in a selected folder joewoods Word VBA 13 05-16-2016 06:29 PM
Saving PPT as a looping video Frank Bugek PowerPoint 0 08-23-2015 08:04 PM
Looping through a folder of PDF files and saving them as docx Word Mac saving as PDF not docx Gweilo Word 3 02-16-2015 03:38 PM
Looping through a folder of PDF files and saving them as docx Problem saving docx files in Win 7 donkrafft Word 12 02-05-2010 05:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft