Application.FileSearch.Lookin - Point to network path?

strorg

Board Regular
Joined
Mar 27, 2002
Messages
112
I can map a drive [Z:] to a network location and then using Application.FileSearch.Lookin = "Z:" successfully execute. I would prefer to point to the location using the actual path (Application.FileSearch.Lookin = "\\myserver\myfolder\mysubfolder") but the search does not return any files? Any thoughts?

Thanks...Tom
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Without seeing the rest of your code we cannot be sure that you are using it correctly. The above line suggests not.

Click in the word "Filesearch" in your module and press F1 key to get help.
 
Upvote 0
I have a drive mapped as "Z:". If I enter "Z:" in the Range("CurrentYear") cell the code works fine. If I enter the actual network path in the Range("CurrentYear") cell, no files are found. I am entering the network path exactly as I am mapping it.

Thanks...Tom

Code:
Sub CopyFromLIMS()

Application.StatusBar = "Searching for files..."
myYear = Range("CurrentYear").Text

With Application.FileSearch
    .NewSearch
    .LookIn = Range("InputFolder").Text
    .SearchSubFolders = False
    .Filename = "*_" & myYear & "_*.txt"
    '.MatchTextExactly = True
    '.FileType = msoFileTypeAllFiles
    
    If .Execute() = 0 Then response = MsgBox("There were no files found.", vbOKOnly, "File Search")
    If .Execute() > 0 Then response = MsgBox("There were " & .FoundFiles.Count & " file(s) found. Click OK to proceed or Cancel to quit.", vbOKCancel, "Import and process files...")
        If response <> 1 Then Application.StatusBar = False
        If response <> 1 Then Exit Sub
    

'Copy the files from StarLIMS
        Set fso = CreateObject("Scripting.FileSystemObject")
        For i = 1 To .FoundFiles.Count
            Application.StatusBar = "Processing file " & i & " of " & .FoundFiles.Count & "."
            myFileName = .FoundFiles(i)
            
            'On Error Resume Next
            With fso
                .copyfile myFileName, Range("ProcessFolder").Text
            End With
        Next i
        Set fso = Nothing
        Application.StatusBar = False
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,383
Messages
6,119,196
Members
448,874
Latest member
Lancelots

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