2012-12-07 5 views
0

에 좀 제품 ID 코드VLOOKUP 외부 폴더

100-10R 23P901 와 엑셀 시트 ......

나는 제품 이미지가 저장되는 폴더가 있습니다. 그림의 시작 부분에는 제품 코드가 있지만 끝은 다를 수 있습니다.

제품 폴더의 외부 폴더에있는 사진을 Vloopup 할 수 있는지 아는 사람이 있습니까?

+2

아니요. VLookup은 파일 시스템이 아니라 통합 문서의 데이터와 작동하도록 설계되었습니다. 외부 폴더에있는 모든 파일의 이름을 가진 시트를 작성했다면이 작업을 수행하고 싶지 않은 경우 VBA – NickSlash

+0

감사 Nick을 사용해야합니다. VBA 기본 사항을 알고 있습니다. 이런 식으로 코드가 상대적으로 복잡합니까? 아니면 제가 살펴 봐야합니까? – user1783504

답변

0

FileSystemObject를 조사해야 FileSystem 관련 작업을 볼 수 있습니다.

나는 완전히 확신하지 못했기 때문에 당신이하려고 한 것과 같은 것을하지는 않겠지 만, 빠른 예제를 만들었습니다. 이해하기가 쉽기를 바랍니다.

다음 코드를 모듈 안에 배치하면 워크 시트의 "checkList"기능에 액세스 할 수 있습니다.

checkList 함수는 지정된 폴더의 파일 이름 목록을 캐시하여 반복하며 "Name"매개 변수가 목록에 저장된 항목과 일치하는지 확인합니다.

파일 목록 (FileList 컬렉션)은 checkList가 처음 loadList 하위에 의해 호출 될 때 한 번 채워집니다.

loadList 하위는 지정된 폴더를 읽고 모든 파일 이름을 컬렉션에 추가합니다.

' Global Variable, used to cache the filenames 
Public FileList As Collection 

' this function returns "" if no match was found, and returns the file name if found. 
Public Function checkList(ByVal Name As String) As String 
Dim Result As String 
Dim Item As Variant 

    Result = "" 

    If FileList Is Nothing Then 
     loadList 
    End If 

    For Each Item In FileList 
     ' Performs a simple match on the filename, probably needs to be adjusted! 
     If Item Like Name & "*" Then 
      Result = Item 
     End If 
    Next Item 

    checkList = Result 

End Function 
' populates the FileList collection 
Public Sub loadList() 
Dim FSO As Object 
Dim Folder As Object 
Dim File As Object 

If FileList Is Nothing Then 
    ' First Run, needs to be created 
    Set FileList = New Collection 
Else 
    ' Should not happen unless you call it manually. 
    Set FileList = Nothing ' Clear up the old list 
    Set FileList = New Collection ' Create a new empty one 
End If 

Set FSO = CreateObject("Scripting.FileSystemObject") 
' Change "C:\" to the location of the folder you want to search 
Set Folder = FSO.GetFolder("C:\") 

For Each File In Folder.Files 
    ' Add the name to the FileList 
    FileList.Add File.Name 
Next 

End Sub 
관련 문제