List Files (Specific File Type) from Folder & Sub-folders to Excel w/ VBA

acerlaptop

New Member
Joined
Feb 17, 2020
Messages
44
Office Version
  1. 2013
Platform
  1. Windows
Hi Guys,

Anybody knows how to list all the PDF Files from a Folder and its Sub-folders to the Excel with VBA?

Thank you
 
Anyway, where do I put this code on the first code you gave?

The 2 lines are in the code provided in post#6 - both lines require amending as indicated in post#9

I ask the file count so i'll know if there are multiple versions of 1 file to so I can check which one is valid.
Why "forget about that" ?
- it does not solve your problem

Try this formula in E2 and copy down
- does it give you what you need ?
=IFERROR(VALUE(RIGHT(SUBSTITUTE(A2,"."&B2,""),1)),"")
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
The 2 lines are in the code provided in post#6 - both lines require amending as indicated in post#9


Why "forget about that" ?
- it does not solve your problem

Try this formula in E2 and copy down
- does it give you what you need ?
=IFERROR(VALUE(RIGHT(SUBSTITUTE(A2,"."&B2,""),1)),"")


The code returns now an error. It says Object doesn't support thes property of method.

VBA Code:
=IFERROR(VALUE(RIGHT(SUBSTITUTE(A2,"."&B2,""),1)),"")
 
Upvote 0
The 2 lines are in the code provided in post#6 - both lines require amending as indicated in post#9


Why "forget about that" ?
- it does not solve your problem

Try this formula in E2 and copy down
- does it give you what you need ?
=IFERROR(VALUE(RIGHT(SUBSTITUTE(A2,"."&B2,""),1)),"")

Don't mind my previous reply. The code works now. Thanks.

By the way. As I'm studying VBA right now, I'm trying to understand your code, but I'm having a really hard time. :)
 
Upvote 0
Upvote 0
T
FileSystemObject is probably not the easiest place to start learning!!
Thanks for this. Can I continue this thread but with different topic? :)

Also, Can your make your previous code so that it disregards Temp files (files with ~ in name).

thanks
 
Last edited:
Upvote 0
Can your make your previous code so that it disregards Temp files (files with ~ in name).

Wrap around required for If Err.Number = 0 Then .... = Array(file.Name, extn, file.DateCreated, Replace(file.path, file.Name, ""))
VBA Code:
        If InStr(file.Name, "~") = 0 Then
            If Err.Number = 0 Then Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Resize(, 4) = Array(file.Name, extn, file.DateCreated, Replace(file.path, file.Name, ""))
        End If

Can I continue this thread but with different topic?
No ;)
 
Upvote 0
T
Wrap around required for If Err.Number = 0 Then .... = Array(file.Name, extn, file.DateCreated, Replace(file.path, file.Name, ""))
VBA Code:
        If InStr(file.Name, "~") = 0 Then
            If Err.Number = 0 Then Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Resize(, 4) = Array(file.Name, extn, file.DateCreated, Replace(file.path, file.Name, ""))
        End If


No ;)

Thanks :)
 
Upvote 0
Wrap around required for If Err.Number = 0 Then .... = Array(file.Name, extn, file.DateCreated, Replace(file.path, file.Name, ""))
VBA Code:
        If InStr(file.Name, "~") = 0 Then
            If Err.Number = 0 Then Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Resize(, 4) = Array(file.Name, extn, file.DateCreated, Replace(file.path, file.Name, ""))
        End If


No ;)
Hi Yongle,
maybe you can help me.

I found your previous VBA-code very useful, but I would like to know how to customize it for my proposal.
First of all, I changed your Code to this:
No Cells.Clear (that is important for my proposal);)

however, my excel sheet hast 5 columns, like
ColumnA, empty
ColumnB, File name
ColumnC, Type
ColumnD, Created
ColumnE, File Path

Second of all, I need some change in your code like:

status​
Already File in the list​
Created​
New added File​
1 (folder got new file)
-​
-​
+​
2 (Created of files changed & folder got new files)
-​
+​
+​
3 (nothing happened msgBox)
-​
-​
-​

1) If
files in the list (Created) didn’t change but the folder got some new files, then add new files at the end of empty Row.
2) ElseIf
Files (Created) did change in the list and the folder got some new files then
-add new files at the end of empty Row and
-update the cell belong to the file with Created
3) Else
files in the list (Created) didn’t change and the folder didn’t get any new files, then msgBox = no change at all.

Thx for your help
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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