
converting an object variable (name of a file) into a string variable
Hi Barth,
Try replacing
For Each varFile In _
Application.FileSearch.FoundFiles
If Left(GetName(CStr(varFile)), 1) = Me.txtFirstLetter Then
Me.lstFileList.AddItem Mid(varFile, _
Len(Application.ActiveDocument.Path) + 2)
End If
Next varFile
with:
For Each varFile In _
Application.FileSearch.FoundFiles
If Left(Mid(varFile, Len(Application.ActiveDocument.Path) + 2) =
Me.textFirstLetter Then
Me.lstFileList.AddItem Mid(varFile,
Len(Application.ActiveDocument.Path) + 2)
End If
Next varFile
Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.
Hope this helps,
Doug Robbins - Word MVP
Quote:
> Is there anyway of converting an object variable (the name of a file) into
a
> string variable. I have tried to use CStr(varFile) but that doesn't seem
to
> work.
> The sub below uses a command button that refers to a textbox
> Me.txtFirstLetter. The user enters the first letter of a patients last
name
> and all the files with names of patients whose last name begin with this
> letter are to appear in the listbox Me.lstFileList
> Private Sub cmdBuildList_Click
> Dim varFile As Variant
> Me.lstFileList.Clear
> With Application.FileSearch
> .NewSearch
> .LookIn = Application.ActiveDocument.Path
> .FileType = msoFileTypeAllFiles
> .SearchSubFolders = False
> .Execute
> End With
> 'GetName Function takes the file name and parses it so that the
> 'new name looks like "LastName,FirstName"
> For Each varFile In _
> Application.FileSearch.FoundFiles
> If Left(GetName(CStr(varFile)), 1) = Me.txtFirstLetter Then
> Me.lstFileList.AddItem Mid(varFile, _
> Len(Application.ActiveDocument.Path) + 2)
> End If
> Next varFile
> End Sub
> Is there an easier way to do this?
> thanks in advance, Barth