2014-09-09 2 views
2

이 작업을 수행하는 데 몇 가지 코드를 사용했지만 작동하지 않습니다. 저는 Windows 7을 운영 중이며 2010 년을 능가합니다 (Office 2010). 내 코드 :VBA Zip 파일 읽기

Public Sub GetZipContents() 
    Dim oApp As Shell32.Shell 
    Set oApp = New Shell32.Shell 
    Dim strFile As String 
    Dim xFname 
    Dim xRow As Long 
    Dim newRow As Long 
    Dim rNew As Range 
    Dim fileNameInZip 
    Dim oFolder As Variant 
    Dim i As Integer 
    i = 1 
    xRow = 0 
    Set fd = Application.FileDialog(msoFileDialogFilePicker) 
    fd.Title = "Select the zip to get file names from" 
    fd.Filters.Clear 
    fd.Filters.Add "Zip Files", "*.zip" 
    fd.FilterIndex = 1 
    If fd.Show = -1 Then 
     strFile = fd.SelectedItems(1) 
     oFolder = oApp.Namespace(strFile).Items 
     Range("A" & i).Value = strFile 
     i = i + 1 
     For Each fileNameInZip In oFolder 
      Range("A" & i).Value = fileNameInZip 
      i = i + 1 
     Next 
     Set oApp = Nothing 
    End If 

End Sub 

또한 fileNameInZip을 Variant로 사용했지만 결과는 같습니다. 내가 선택한 zip 파일에 상관없이, 내 출력 (텍스트 버전이 첨부되어 있으며, 스크린 샷이 더 좋지만 첫 번째 게시물이므로 이미지를 첨부 할 수 없습니다. 첫 번째 줄은 zip 파일의 이름이고, 다음은 이름 공간 호출의 항목)은 항상 동일합니다. 내가 본 모든 사이트는 대답과 비슷한 코드를 가지고 있기 때문에 나는 손실에 처해있다. 어떤 아이디어가 진행되고 있습니까 (파일은 일반적으로 & 열기 등이 아닌 일반적으로 pdfs입니다)?

C : \ 사용자 \ PGibson \ 다운로드 \ CW985786-T-00136.zip

& 열기

구리 & t

& 복사

& 삭제

P & roperties

표시된 라인에 Set 누락

답변

1

...

Public Sub GetZipContents() 
    Dim oApp As Shell32.Shell 
    Set oApp = New Shell32.Shell 
    Dim strFile As String 
    Dim xFname 
    Dim xRow As Long 
    Dim newRow As Long 
    Dim rNew As Range 
    Dim fileNameInZip, fd 
    Dim oFolder As Variant 
    Dim i As Integer 

    i = 1 
    xRow = 0 
    Set fd = Application.FileDialog(msoFileDialogFilePicker) 
    fd.Title = "Select the zip to get file names from" 
    fd.Filters.Clear 
    fd.Filters.Add "Zip Files", "*.zip" 
    fd.FilterIndex = 1 
    If fd.Show = -1 Then 
     strFile = fd.SelectedItems(1) 
     Set oFolder = oApp.Namespace(strFile).Items '< Set! 
     Range("A" & i).Value = strFile 
     i = i + 1 
     For Each fileNameInZip In oFolder 
      Range("A" & i).Value = fileNameInZip 
      i = i + 1 
     Next 
     Set oApp = Nothing 
    End If 

End Sub 
+0

감사합니다 !!!! 나는 정말로 VBA 코더가 아니며 때때로 구문 오류가 나를 찾기가 어렵다. "Set"이 누락 된 이상한 결과. –