Discussion Locked

Path display

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Is there code that shows the path to a file, folder or document keyed in by a user? I am interested in vbscript, visual basic for applications or visual basic - whatever works.

4 replies

by graemeh

Apologies if this turns out to be a repost; having a few problems here!

This is one way to approach it:

Sub FindFile()
Dim sFileName As String
Dim x As Integer
Dim sFile As String

sFileName = "test data.xls"
WithApplication.FileSearch
.Filename = sFileName
.LookIn = "C:\"
.SearchSubFolders = True
x = .Execute
If x = 1 Then
'found it
sFile = .FoundFiles(1)
ElseIf x > 1 Then 'more than one found; FoundFiles contains all the pathnames
ElseIf x = 0 Then
'not found
End If
End With
End Sub

You need to modify filenames/drives as needed or change to a function.

HTH

graeme

by graemeh

BTW, this was done using VBA inside Excel but should work from any VB/VBA/VBScript flavour.

This discussion is closed to new replies.