Help with error when extracting from a zip file

JARichard74

Board Regular
Joined
Dec 16, 2019
Messages
100
Office Version
  1. 365
Platform
  1. Windows
The code is supposed to extract the first line of each .txt files found in the folders inside the zip file. The zip file contains folders, sub-folders, sub-sub-folders containing .txt, .xls and .pdf files. The txt file I need is located in the first set of folders. The code worked well and as far as I know I have not changed anything. Now I started a error 76, Path not found on line "Set xFolder = xFSO.GetFolder(FolderNameInZip)" Then all of sudden it started working again. Any idea what might be causing this?

VBA Code:
Sub ExtractProponents()
Dim R As Long, PathFilename As Variant, FolderNameInZip As Variant, oApp As Object, CompanyName As String
Dim I As Integer, a As Integer, fileNumber As Long
Dim proptblloc As Range
Dim proptbl As ListObject
Dim xFSO As Object, xFolder As Object, xFile As Object, Filename As Object

Application.ScreenUpdating = False
Application.AutoCorrect.AutoFillFormulasInLists = False

Set proptbl = ThisWorkbook.Worksheets("Prep").ListObjects("Proponents")
Set proptblloc = proptbl.HeaderRowRange.Find("No.")
a = proptblloc.Row

PathFilename = Application.GetOpenFilename("ZipFiles (*.zip), *.zip")
If PathFilename = "False" Then Exit Sub
R = Cells(Rows.Count, "A").End(xlUp).Row
Set oApp = CreateObject("Shell.Application")
For Each FolderNameInZip In oApp.Namespace(PathFilename).items
    Set xFSO = CreateObject("Scripting.FileSystemObject")
    Set xFolder = xFSO.GetFolder(FolderNameInZip)
    If xFolder.Files.Count > 1 Then
    For Each xFile In xFolder.Files
        If Right(xFile, 4) = ".txt" Then
        fileNumber = FreeFile
        Open xFile For Input As #fileNumber
        Line Input #1, CompanyName
        I = I + 1
        Cells(I + a, "B").Value = CompanyName
        End If
    Next
    Close #fileNumber
    End If
Next
Set oApp = Nothing
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Watch MrExcel Video

Forum statistics

Threads
1,130,172
Messages
5,640,584
Members
417,152
Latest member
DayTimeSeby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top