VBA读取一个Zip文件

我已经看到了一些代码来做到这一点,但对我来说这是行不通的。 我正在运行Windows 7和Excel 2010(从办公室2010)。 我的代码:

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,但输出是相同的。 无论我select的zip文件,我的输出(文本版本附加,屏幕截图更好,但我不能附加图像,因为这是我的第一篇文章…第一行是压缩文件的名称,下一个命名空间调用中的项目)始终是相同的。 我感到不知所措,因为我看过的每个站点都有类似的代码。 任何想法正在发生(其中的文件通常是PDF格式,而不是打开等)?

C:\用户\ PGibson \下载\ CW985786-T-00136.zip

&打开

&复制

&删除

P&roperties

缺less在标记行上Set

 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