Hi guys,
I want to make automation on a single directory which contains a lot of folder. Heres the scenario.
directory = contains a lot of folders.
folders = contains images.
What I wanted to do is to just enter the folder filename into inputbox and then the macro will search the entire directory and if the folder is found automatically it will be selected and load its content(images) filename to a listbox.
Any idea how will I search and select a folder?
After some research I got this code but I dont know how will I incorporate it with the below code.
[vba]
Sub FindFiles()
Dim strDocPath As String
Dim strCurrentFile As String
Dim fname as Strinf
fname = InputBox ("Input Folder Name")
strDocPath = "c:\temp\"
strCurrentFile = Dir(strDocPath & fname)
Do While strCurrentFile <> ""
MsgBox strCurrentFile
strCurrentFile = Dir
Loop
End Sub
[/vba]
Incorporate in this code
[vba]
Dim MyFolder As String
Dim MyFile As String
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then
lstImages.Clear
txtDir.Text = .SelectedItems(1)
MyFile = Dir(.SelectedItems(1) & "\*.jpg")
Do While MyFile <> ""
lstImages.AddItem MyFile
MyFile = Dir
Loop
End If
End With
[/vba]
Instead of selecting a folder, it will be prompt with InputBox to enter a folder name, then search and if found select.
Thanks.