Help with error when extracting from a zip file

JARichard74

Board Regular
Joined
Dec 16, 2019
Messages
114
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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
Back
Top