안녕하세요?
지식인에 올라왔던 질문인데 많이 사용될듯 해서 올려둡니다.
해당 압축파일을 다운받아서 특정폴더에서 풀면 엑셀파일하나, 그림파일하나, 그리고 JPG폴더가 생성되고
생성된 폴더내엔 그림파일이 몇개 있을겁니다.
유저폼을 띄워 검색창에 소나무를 입력후 검색을 클릭하면 JPG폴더내에 있는 소나무란 단어가 들어간
그림파일은 모두 리스트박스에 나타납니다.
이때 리스트박스의 해당 파일이름을 클릭하면 우측에 해당파일의 그림이 나타납니다.

현업에선 JPG폴더에 그림파일을 복사해 두고 사용하시면 되겠죠?
아래는 해당파일의 코드입니다.
Option Explicit
Private Sub CommandButton1_Click()
Dim FleName As String, MyPath As String
Dim i As Integer
Dim x As Variant
Application.ScreenUpdating = False
Me.ListBox1.Clear
Me.Image1.Picture = LoadPicture(ThisWorkbook.Path & Application.PathSeparator & "재밌는_엑셀.jpg")
MyPath = ThisWorkbook.Path & Application.PathSeparator & "JPG" & Application.PathSeparator
x = GetFileList(MyPath & "*" & Me.TextBox1.Value & "*.jpg")
Select Case IsArray(x)
Case True
For i = LBound(x) To UBound(x)
Me.ListBox1.AddItem x(i)
Next i
Case False
MsgBox "해당하는 문서가 없습니다."
End Select
Application.ScreenUpdating = True
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub ListBox1_Click()
Dim Str As String
Str = ThisWorkbook.Path & Application.PathSeparator & "JPG" & Application.PathSeparator
Me.Image1.Picture = LoadPicture(Str & Me.ListBox1.Value)
End Sub
Function GetFileList(FileSpec As String) As Variant
Dim FileArray() As Variant
Dim FileCount As Integer
Dim FileName As String
On Error GoTo NoFilesFound
FileCount = 0
FileName = Dir(FileSpec)
If FileName = "" Then GoTo NoFilesFound
Do While FileName <> ""
FileCount = FileCount + 1
ReDim Preserve FileArray(1 To FileCount)
FileArray(FileCount) = FileName
FileName = Dir()
Loop
GetFileList = FileArray
Exit Function
NoFilesFound:
GetFileList = False
End Function
Private Sub UserForm_Initialize()
Me.Image1.Picture = LoadPicture(ThisWorkbook.Path & Application.PathSeparator & "재밌는_엑셀.jpg")
End Sub
그럼 또...!
======================================================================================
첨부파일
090715_그림파일_검색하기_VBA.zip
======================================================================================
첫댓글 감사합니다^^ 유용하게 쓰겠습니다
조금이나마 도움이 되셨으면 좋겠군요... 즐거운 하루 되세요... ^^*
고맙습니다. 많은 도움 되었습니다.
한 가지 궁금점이 있습니다. 이 파일에서 숫자 혹은 영어로 검색가능하게 하려면 어떻게 수정하면 될까요? Dim x 이 구문을 변경해야 하나요?
Variant라 수정없이 사용하셔도 될듯 합니다...