Loop through files in a folder based on date

creyn

Board Regular
Joined
Sep 16, 2016
Messages
127
I am trying to loop through Files in Folder based upon date that is entered in the Form. Below is the code I am using. I am having an issue with getting the files to be visible. Anyone help is greatly appreciated.

With fDialog
.Title = ""
.AllowMultiSelect = False
Intialfilename = ""

If IsNull(Me.Text6.Value) Then
MsgBox "Date cannot be empty. Please select date in order to proceed with this process."
ElseIf .Show = True Then
varfile = .SelectedItems(1) & "*\data*\ " & Me.Text6.Value
strFolder = varfile
Else
rtn = SysCmd(4, "Action aborted by user")
Exit Sub
End If
 
Yes, I am picking one folder. Then in that folder, there are several folders which each contain files that I am trying to pull. So, instead of the using the File Picker and be forced to pick each file one at a time, I am trying to build my code to get through and find each file that matches this criteria: S:\zCorey\TDD Testing Folder*\data\fof*


The fof is what each file begins with in each folder. I hope what I said makes some sort of sense?
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
that search string matches subfolders in more than one parent folder.
What is the folder you are picking (in this example?)
 
Upvote 0
Okay, I'm going to assume you are searching for files in TDD Testing Folder.

What does the date have to do with this now?
I am trying to loop through Files in Folder based upon date that is entered in the Form.

Is that supposed to be a created date? a modified date? Something that shows up in the file names?
 
Upvote 0
Yes, I am searching for files in the TDD Testing Folder. I am looking to loop through the files within the folders based upon a Date that is entered.
 
Upvote 0
What does the date mean? Is that supposed to be a created date? a modified date? Something that shows up in the file names?
 
Upvote 0
Surprised your code does not error on use or compiling since you are missing an End With.
Have used this a few times (msoFileDialogFolderPicker) and IIRC, you cannot see files using it. It's for choosing a folder only. To see files, you need the msoFileDialogFilePicker, which only lets you choose one or more files and not just the folder. There is a method posted that looks like this (I modified it slightly to eliminate compile errors). It does what you're asking for (returning a folder name while showing files) but it's not as pretty. You should be able to modify it if you need it to start at a particular folder.

Code:
Dim objShell
Dim objFldr
Dim objMyDocs
Dim pathMyDocs As String

Set objShell = CreateObject("Shell.Application")
Set objMyDocs = objShell.Namespace(&H5)
pathMyDocs = objMyDocs.Self.Path

On Error Resume Next
Set objFldr = objShell.BrowseForFolder(0, "pick me", &H4001, pathMyDocs)

If Not (objFldr Is Nothing) Then
  MsgBox objFldr.Items.Item.Path
End If

Set objFldr = Nothing
Set objShell = Nothing
End Sub
 
Last edited:
Upvote 0
Micron, he's trying NOT to use a file picker. :)

Yes, I am picking one folder. Then in that folder, there are several folders which each contain files that I am trying to pull. So, instead of the using the File Picker and be forced to pick each file one at a time, I am trying to build my code to get through and find each file that matches this criteria: S:\zCorey\TDD Testing Folder*\data\fof*
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,940
Members
451,730
Latest member
BudgetGirl

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