Loop through subfolders - open PDFs

gxm204

New Member
Joined
Nov 20, 2015
Messages
29
Hello,

I am exporting some PDFs that I am then importing into Excel to do some data cleaning (removing headers, subtitles, etc.)

When I do the export from Bloomberg, I am getting a subfolder for each PDF document. So I would want to be able to run through all the subfolders and do my data cleaning program.

What would be the best way to do this, it sounds like a good job for VBA -- still learning the language, though.

Thanks everyone.

Best,
George
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Here is a recursive subfolder processing example. The part "Operate on each file" will let you run code on every file in every sub folder. You can also add logic here to exclude any errant files you come across.

Code:
<code>
Sub Main()
Dim FileSystem As Object
Dim HostFolder As String

HostFolder = "C:\"

Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
End Sub

Sub DoFolder(Folder)
    Dim SubFolder
    For Each SubFolder In Folder.SubFolders
        DoFolder SubFolder
    Next
    Dim File
    For Each File In Folder.Files
        ' Operate on each file
    Next
End Sub</code>
 
Last edited:
Upvote 0
That's a big job for a new coder.

Post 32's code gets you to the batch process.

What your macro needs to do is to import the content of the PDF file. Not all files have content that can be imported.

Do you have Acrobat, not the reader? If not, then you are stuck with the unrealiable SendKeys() method to "import" the contents or maybe some other 3rd party program.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,947
Members
448,534
Latest member
benefuexx

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