下面编写的代码使用用户提供的名称搜索文件并将其显示在消息框中。是否可以将其存储在一个数组中,以便在需要时,可以打开并循环打开搜索结果文件以读取搜索结果文件的内容?
Private Sub cmdsubmit_Click()
If Me.PART_NUMBER.Value = "" Then
MsgBox "Please enter the Part Number.", vbExclamation, "PART SEARCH"
Me.PART_NUMBER.SetFocus
Exit Sub
End If
If Me.ID_TAG.Value = "" Then
MsgBox "Please Select a ID TAG.", vbExclamation, "PART SEARCH"
Me.ID_TAG.SetFocus
Exit Sub
End If
Call flist
End Sub
Sub flist()
Dim myList
Dim fldr As String, fltr As String, sTemp As String, sHldr As String
Dim i As Long
Dim msg As String
Dim FileCount As Integer
FileCount = 0
fldr = "C:\Users\op\Desktop\New folder"
If Right$(fldr, 1) <> "\" Then fldr = fldr & "\"
fltr = (Me.PART_NUMBER.Value & "*.xls")
msg = fltr & " files found:" & vbLf
sHldr = Dir(fldr & fltr)
Do While sHldr <> ""
sTemp = sTemp & "|" & sHldr
sHldr = Dir
Loop
If sTemp <> "" Then
myList = Split(sTemp, "|")
For i = 1 To UBound(myList)
msg = msg & vbLf & myList(i)
Next i
Else
msg = msg & vbLf & "None"
End If
MsgBox msg
End Sub