How to pull data from everchanging folder and file?

Phoenix71

New Member
Joined
Mar 1, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have searched all over to find an answer to this conundrum. I have a excel file that is created by a report. The file is saved in a folder, that folder is in a specific location but the folder name changes everytime the report is ran, usually 2 - 3 times per day. The Filename and folder that it is in are always the same, based on date and how many reports have been ran. Example 2022-1-1_1, 2022-1-1_2, and so on and so on. I need to be able to pull data from the most recent report. I have found plenty of examples for a changing filename, but nothing for a folder name that changes. I am not looking for anyone to write my macro. I just need to be guided n the right direction. I'll figure it out from there. I am still new to this and am wiling to do the work to learn. Just need a push in the right direction.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I have found plenty of examples for a changing filename, but nothing for a folder name that changes.
As the logic is the same, for example just using the VBA Dir function …​
 
Upvote 0
here you retrieve an array c01 with all your subdirectories.
With "Filter" you can do a little bit finetuning.
VBA Code:
Sub M_snb()
     c00 = "c:\forum"                                     '---> your startsubdirectory (without spaces !!!)"
     c01 = Split(CreateObject("wscript.shell").exec("cmd /c dir " & c00 & " /a:d/b/s").stdout.readall, vbCr)
     Range("A1").Resize(UBound(c01) + 1).Value = Application.Transpose(c01)
End Sub
 
Upvote 0

Forum statistics

Threads
1,202,984
Messages
6,052,914
Members
444,612
Latest member
FajnaAli

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