Find certain folder but don't know the full path

elmnas

Board Regular
Joined
Feb 20, 2015
Messages
206
Hello All Excel Members,

If you see on my picture below:

x5vX98x.png


I got a certain folder structure,

The thing is I got a string I alert which can be any number.

then I need to open the correct folder in explorer and unzip a file called. test.zip

Could someone help me with a code to open correct folder example folder 34118 :)

there can be xxxxx numbers of folders

Thank you in advance
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
to search through your windows explorer you must add in the correct reference in VBA.

the below should get you to the right file but as far as opening the correct file id need more info. hopeully this is a good start for you.

Code:
Sub ListFilesInFolder()
     
     
    Dim FS As Scripting.FileSystemObject
    Dim SourceFolder As Scripting.Folder
    Dim FileItem As Scripting.File
    Dim r As Long
    Dim filenumber As Long
    filenumber = InputBox("whats the file number you are looking for?")
    Set FS = New Scripting.FileSystemObject
    Set SourceFolder = FS.GetFolder("U:") & filenumber 'Place in here the directory of interest
    For Each FileItem In SourceFolder.Files
       If FileItem.Type = "Microsoft Excel Worksheet" Then
       FileItem.Copy FileItem.Name, True
       Application.Workbooks.Open (FileItem.Name)
       End If
    Next FileItem
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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