Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help with file search / Dir()
I need some help with the following code:
' Dim myCount As Long ' ' If (Lbx_file_names.Value < "") Then ' Adobe_Filename_Pick = Lbx_file_names.Value ' End If ' Lbx_file_names.Clear MyFolder = "X:\Omar\Finished_Flanges\" ' 'myFile = Dir(myFolder & "*.pdf") MyFile = Dir(MyFolder & Flange_sname & ".pdf") ' myCount = 0 If MyFile < "" Then Do myCount = myCount + 1 Lbx_file_names.AddItem MyFile ' MyFile = Dir() Loop While MyFile < "" End If ' I want to search the directory X:\Omar\Finished_Flanges\ and all of its subdirectories. I think i can do it with filesearch but am not sure. Please offer some suggestions. Thanks, Omar |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help with file search / Dir()
Hello Omar,
Not exactly sure what you are attempting to do but perhaps the following code example that I think originated from Jacob Skaria will help to point you in the right direction. I tried to find the post but failed so here is a copy of it. Sub findfile() Dim Addlinks 'Directory to start searching strFolder = CurDir RowCount = 1 Do Mode = InputBox("What type of search do you want to perform?" & vbCrLf & _ "1: list of folders only" & vbCrLf & _ "2: list of files only" & vbCrLf & _ "3: list of files and folders only") Loop While Mode < 1 Or Mode 3 If Mode = 2 Or Mode = 3 Then Addlinks = MsgBox("Do you want to include Hyperlinks?", vbYesNo, _ Title:=Hyperlinks) Else Hyperlinks = vbNo End If Set fso = CreateObject _ ("Scripting.FileSystemObject") Set folder = _ fso.GetFolder(strFolder) Columns("A:A").Clear 'Clear All required to clear hyperlinks from previous run of code Call GetWorksheetsSubFolder(strFolder + "\", Mode, Addlinks, RowCount) End Sub Sub GetWorksheetsSubFolder(strFolder, Mode, Addlinks, ByRef RowCount) Set fso = CreateObject _ ("Scripting.FileSystemObject") Set folder = _ fso.GetFolder(strFolder) If Mode = 1 Or Mode = 3 Then Range("A" & RowCount) = strFolder RowCount = RowCount + 1 End If If folder.subfolders.Count 0 Then For Each sf In folder.subfolders On Error GoTo 100 Call GetWorksheetsSubFolder(strFolder + sf.Name + "\", Mode, Addlinks, RowCount) 100 Next sf End If 'folder size in bytes On Error GoTo 200 If Mode = 2 Or Mode = 3 Then For Each fl In folder.Files If Addlinks = vbYes Then With ActiveSheet .Hyperlinks.Add Anchor:=.Range("A" & RowCount), Address:=fl.Path, TextToDisplay:=fl.Path End With Else Range("A" & RowCount) = fl End If RowCount = RowCount + 1 Next fl End If 200 On Error GoTo 0 End Sub -- Regards, OssieMac |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
file search or search files | Excel Discussion (Misc queries) | |||
File Search | Excel Programming | |||
Search a FAQ file | Excel Worksheet Functions | |||
Turning a text file name into a search and linking the file as a hyperlink | Excel Discussion (Misc queries) | |||
Macro to search from one file & place on another file. | Excel Programming |